# matterport/mask_rcnn architecture

> Architecture diagram of the GitHub repository matterport/mask_rcnn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/matterport/mask_rcnn
- Repository: https://github.com/matterport/mask_rcnn

## Overview

This repository is a Keras/TensorFlow Mask R-CNN implementation for object detection and instance segmentation, with examples for inference, training, and evaluation. Users provide images to a configured model, which returns per-instance boxes, classes, scores, and masks; visualization helpers can display those results. Training examples adapt datasets and configurations, while the COCO example also supports AP evaluation. The README documents the detection stages, but excerpts do not expose their complete internal call graph, so stage links cite the README; unsampled sample implementations are represented only at their supported directory paths.

Main entry points: [`mrcnn/model.py`](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py) (Mask R-CNN model), [`mrcnn/utils.py`](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/utils.py) (Dataset interface), [`samples/coco/coco.py`](https://github.com/matterport/mask_rcnn/blob/master/samples/coco/coco.py) (COCO train/evaluate), [`mrcnn/config.py`](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/config.py) (Model configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Detection model"]
  node_model["Mask R-CNN model<br/>[model.py]"]
  node_rpn["Region proposals<br/>[model.py]"]
  node_classifier["Box classification<br/>[model.py]"]
  node_masks["Instance masks<br/>[model.py]"]
  node_results["Detection results<br/>[model.py]"]
end

subgraph group_data["Data and configuration"]
  node_config["Model configuration<br/>[config.py]"]
  node_dataset["Dataset interface<br/>[utils.py]"]
  node_preprocess["Image preparation<br/>[utils.py]"]
end

subgraph group_use["Examples and evaluation"]
  node_coco["COCO train/evaluate<br/>[coco.py]"]
  node_custom["Custom datasets"]
  node_balloon["Balloon example<br/>[balloon.py]"]
  node_nucleus["Nucleus example<br/>[nucleus.py]"]
  node_shapes["Shapes example<br/>[shapes.py]"]
  node_coco_metrics["COCO AP metrics<br/>[coco.py]"]
end

subgraph group_support["Visualization and parallelism"]
  node_visualize["Result visualization<br/>[visualize.py]"]
  node_parallel["Multi-GPU training<br/>[parallel_model.py]"]
end

node_user(("Image user"))

node_user -->|"provides images"| node_preprocess
node_preprocess -->|"prepares inputs"| node_model
node_config -->|"configures"| node_model
node_model -->|"generates proposals"| node_rpn
node_rpn -->|"refines boxes"| node_classifier
node_classifier -->|"predicts masks"| node_masks
node_model -->|"returns detections"| node_results
node_results -->|"renders results"| node_visualize
node_model -->|"uses utilities"| node_dataset
node_dataset -->|"supports image prep"| node_preprocess
node_coco -->|"trains and evaluates"| node_model
node_coco -.->|"adapts dataset"| node_dataset
node_coco -->|"reports AP"| node_coco_metrics
node_custom -->|"extends interface"| node_dataset
node_balloon -->|"demonstrates adaptation"| node_dataset
node_nucleus -->|"demonstrates adaptation"| node_dataset
node_shapes -->|"demonstrates adaptation"| node_dataset
node_parallel -->|"replicates model"| node_model

click node_config "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/config.py"
click node_dataset "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/utils.py"
click node_preprocess "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/utils.py"
click node_model "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py"
click node_rpn "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py"
click node_classifier "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py"
click node_masks "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py"
click node_results "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py"
click node_visualize "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/visualize.py"
click node_parallel "https://github.com/matterport/mask_rcnn/blob/master/mrcnn/parallel_model.py"
click node_coco "https://github.com/matterport/mask_rcnn/blob/master/samples/coco/coco.py"
click node_custom "https://github.com/matterport/mask_rcnn/tree/master/samples"
click node_balloon "https://github.com/matterport/mask_rcnn/blob/master/samples/balloon/balloon.py"
click node_nucleus "https://github.com/matterport/mask_rcnn/blob/master/samples/nucleus/nucleus.py"
click node_shapes "https://github.com/matterport/mask_rcnn/blob/master/samples/shapes/shapes.py"
click node_coco_metrics "https://github.com/matterport/mask_rcnn/blob/master/samples/coco/coco.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_model,node_rpn,node_classifier,node_masks,node_results,node_user toneBlue
class node_config,node_dataset,node_preprocess toneAmber
class node_coco,node_custom,node_balloon,node_nucleus,node_shapes,node_coco_metrics toneMint
class node_visualize,node_parallel toneRose
```

## Components

### Detection model

- [Mask R-CNN model](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py): `mrcnn/model.py`
- [Region proposals](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py): `mrcnn/model.py`
- [Box classification](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py): `mrcnn/model.py`
- [Instance masks](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py): `mrcnn/model.py`
- [Detection results](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/model.py): `mrcnn/model.py`

### Data and configuration

- [Model configuration](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/config.py): `mrcnn/config.py`
- [Dataset interface](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/utils.py): `mrcnn/utils.py`
- [Image preparation](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/utils.py): `mrcnn/utils.py`

### Examples and evaluation

- [COCO train/evaluate](https://github.com/matterport/mask_rcnn/blob/master/samples/coco/coco.py): `samples/coco/coco.py`
- [Custom datasets](https://github.com/matterport/mask_rcnn/tree/master/samples): `samples`
- [Balloon example](https://github.com/matterport/mask_rcnn/blob/master/samples/balloon/balloon.py): `samples/balloon/balloon.py`
- [Nucleus example](https://github.com/matterport/mask_rcnn/blob/master/samples/nucleus/nucleus.py): `samples/nucleus/nucleus.py`
- [Shapes example](https://github.com/matterport/mask_rcnn/blob/master/samples/shapes/shapes.py): `samples/shapes/shapes.py`
- [COCO AP metrics](https://github.com/matterport/mask_rcnn/blob/master/samples/coco/coco.py): `samples/coco/coco.py`

### Visualization and parallelism

- [Result visualization](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/visualize.py): `mrcnn/visualize.py`
- [Multi-GPU training](https://github.com/matterport/mask_rcnn/blob/master/mrcnn/parallel_model.py): `mrcnn/parallel_model.py`

### Other components

- **Image user**

## Connections

- Image user → Image preparation: provides images (evidence: `README.md`)
- Image preparation → Mask R-CNN model: prepares inputs (evidence: `mrcnn/model.py`)
- Model configuration → Mask R-CNN model: configures (evidence: `mrcnn/model.py`)
- Mask R-CNN model → Region proposals: generates proposals (evidence: `README.md`)
- Region proposals → Box classification: refines boxes (evidence: `README.md`)
- Box classification → Instance masks: predicts masks (evidence: `README.md`)
- Mask R-CNN model → Detection results: returns detections (evidence: `mrcnn/model.py`)
- Detection results → Result visualization: renders results (evidence: `mrcnn/visualize.py`)
- Mask R-CNN model → Dataset interface: uses utilities (evidence: `mrcnn/model.py`)
- Dataset interface → Image preparation: supports image prep (evidence: `README.md`)
- COCO train/evaluate → Mask R-CNN model: trains and evaluates (evidence: `README.md`)
- COCO train/evaluate → Dataset interface: adapts dataset (evidence: `README.md`)
- COCO train/evaluate → COCO AP metrics: reports AP (evidence: `README.md`)
- Custom datasets → Dataset interface: extends interface (evidence: `README.md`)
- Balloon example → Dataset interface: demonstrates adaptation (evidence: `README.md`)
- Nucleus example → Dataset interface: demonstrates adaptation (evidence: `README.md`)
- Shapes example → Dataset interface: demonstrates adaptation (evidence: `README.md`)
- Multi-GPU training → Mask R-CNN model: replicates model (evidence: `mrcnn/model.py`)
