# facebookresearch/detectron architecture

> Architecture diagram of the GitHub repository facebookresearch/detectron, 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/facebookresearch/detectron
- Repository: https://github.com/facebookresearch/detectron

## Overview

Detectron is a Caffe2 research system for object detection and related instance tasks. Researchers configure a dataset, prepare image and region-of-interest data, build and train or run a detector, then evaluate or visualize predictions. The README names Mask R-CNN, RetinaNet, Faster R-CNN, RPN, Fast R-CNN and R-FCN, with ResNet/ResNeXt, FPN and VGG backbones. Source-index references support the internal connections shown; CLI wiring and several algorithm details are unsampled, so those links are marked unverified.

Main entry points: [`detectron/modeling/model_builder.py`](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/model_builder.py) (Model builder), [`tools/infer.py`](https://github.com/facebookresearch/detectron/blob/main/tools/infer.py) (Inference CLI), [`detectron/modeling/detector.py`](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/detector.py) (Detector runtime), [`detectron/datasets/task_evaluation.py`](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/task_evaluation.py) (Task evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data and evaluation"]
  node_dataset["COCO dataset<br/>[json_dataset.py]"]
  node_catalog["Dataset catalog<br/>[dataset_catalog.py]"]
  node_roidb["Region database<br/>[roidb.py]"]
  node_data_loader["Minibatch loader<br/>[loader.py]"]
  node_minibatch["Minibatch assembly<br/>[minibatch.py]"]
  node_roi_data["ROI targets<br/>[fast_rcnn.py]"]
  node_evaluation["Task evaluation<br/>[task_evaluation.py]"]
  node_json_eval["COCO evaluation"]
  node_city_eval["Cityscapes evaluation"]
  node_voc_eval["VOC evaluation"]
end

subgraph group_models["Detection models"]
  node_model_builder["Model builder<br/>[model_builder.py]"]
  node_detector["Detector runtime<br/>[detector.py]"]
  node_backbones["Backbones and FPN<br/>[FPN.py]"]
  node_resnet["ResNet backbone<br/>[ResNet.py]"]
  node_anchors["Anchor generation"]
  node_algorithm_heads["Detection heads"]
  node_proposal_ops["Proposal operations"]
  node_fpn_ops["FPN proposal routing"]
end

subgraph group_runtime["Training and inference"]
  node_train_cli["Training CLI<br/>[train_net.py]"]
  node_infer_cli["Inference CLI<br/>[infer.py]"]
  node_config["Configuration<br/>[config.py]"]
end

subgraph group_support["Core utilities"]
  node_utility_layer["Tensor and geometry utilities"]
end

node_researcher(("Researcher"))
node_caffe2["Caffe2 framework"]
node_result_user(("Researcher results"))

node_researcher -.->|"starts training"| node_train_cli
node_researcher -.->|"requests inference"| node_infer_cli
node_train_cli -.->|"builds model"| node_model_builder
node_infer_cli -.->|"builds model"| node_model_builder
node_model_builder -->|"reads settings"| node_config
node_dataset -->|"looks up metadata"| node_catalog
node_dataset -->|"creates entries"| node_roidb
node_data_loader -->|"loads minibatches"| node_minibatch
node_minibatch -->|"assembles targets"| node_roi_data
node_model_builder -->|"uses loader"| node_data_loader
node_model_builder -->|"uses minibatches"| node_minibatch
node_model_builder -->|"dispatches heads"| node_algorithm_heads
node_model_builder -->|"creates detector"| node_detector
node_model_builder -->|"selects backbone"| node_backbones
node_backbones -->|"uses backbone"| node_resnet
node_backbones -->|"uses anchors"| node_anchors
node_detector -->|"uses ROI data"| node_roi_data
node_detector -->|"generates proposals"| node_proposal_ops
node_detector -->|"routes proposals"| node_fpn_ops
node_fpn_ops -->|"uses ROI targets"| node_roi_data
node_dataset -->|"uses geometry helpers"| node_utility_layer
node_train_cli -.->|"runs on"| node_caffe2
node_infer_cli -.->|"runs on"| node_caffe2
node_evaluation -->|"dispatches evaluator"| node_json_eval
node_evaluation -->|"dispatches evaluator"| node_city_eval
node_evaluation -->|"dispatches evaluator"| node_voc_eval
node_infer_cli -.->|"evaluates predictions"| node_evaluation
node_infer_cli -.->|"returns detections"| node_result_user

click node_train_cli "https://github.com/facebookresearch/detectron/blob/main/tools/train_net.py"
click node_infer_cli "https://github.com/facebookresearch/detectron/blob/main/tools/infer.py"
click node_config "https://github.com/facebookresearch/detectron/blob/main/detectron/core/config.py"
click node_dataset "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/json_dataset.py"
click node_catalog "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/dataset_catalog.py"
click node_roidb "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/roidb.py"
click node_data_loader "https://github.com/facebookresearch/detectron/blob/main/detectron/roi_data/loader.py"
click node_minibatch "https://github.com/facebookresearch/detectron/blob/main/detectron/roi_data/minibatch.py"
click node_roi_data "https://github.com/facebookresearch/detectron/blob/main/detectron/roi_data/fast_rcnn.py"
click node_evaluation "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/task_evaluation.py"
click node_json_eval "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/json_dataset_evaluator.py"
click node_city_eval "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/cityscapes_json_dataset_evaluator.py"
click node_voc_eval "https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/voc_dataset_evaluator.py"
click node_model_builder "https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/model_builder.py"
click node_detector "https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/detector.py"
click node_backbones "https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/FPN.py"
click node_resnet "https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/ResNet.py"
click node_anchors "https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/generate_anchors.py"
click node_algorithm_heads "https://github.com/facebookresearch/detectron/tree/main/detectron/modeling"
click node_proposal_ops "https://github.com/facebookresearch/detectron/blob/main/detectron/ops/generate_proposals.py"
click node_fpn_ops "https://github.com/facebookresearch/detectron/blob/main/detectron/ops/collect_and_distribute_fpn_rpn_proposals.py"
click node_utility_layer "https://github.com/facebookresearch/detectron/tree/main/detectron/utils"

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_dataset,node_catalog,node_roidb,node_data_loader,node_minibatch,node_roi_data,node_evaluation,node_json_eval,node_city_eval,node_voc_eval toneBlue
class node_model_builder,node_detector,node_backbones,node_resnet,node_anchors,node_algorithm_heads,node_proposal_ops,node_fpn_ops toneAmber
class node_train_cli,node_infer_cli,node_config toneMint
class node_utility_layer toneRose
class node_researcher,node_caffe2,node_result_user toneIndigo
```

## Components

### Data and evaluation

- [COCO dataset](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/json_dataset.py): `detectron/datasets/json_dataset.py`
- [Dataset catalog](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/dataset_catalog.py): `detectron/datasets/dataset_catalog.py`
- [Region database](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/roidb.py): `detectron/datasets/roidb.py`
- [Minibatch loader](https://github.com/facebookresearch/detectron/blob/main/detectron/roi_data/loader.py): `detectron/roi_data/loader.py`
- [Minibatch assembly](https://github.com/facebookresearch/detectron/blob/main/detectron/roi_data/minibatch.py): `detectron/roi_data/minibatch.py`
- [ROI targets](https://github.com/facebookresearch/detectron/blob/main/detectron/roi_data/fast_rcnn.py): `detectron/roi_data/fast_rcnn.py`
- [Task evaluation](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/task_evaluation.py): `detectron/datasets/task_evaluation.py`
- [COCO evaluation](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/json_dataset_evaluator.py): `detectron/datasets/json_dataset_evaluator.py`
- [Cityscapes evaluation](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/cityscapes_json_dataset_evaluator.py): `detectron/datasets/cityscapes_json_dataset_evaluator.py`
- [VOC evaluation](https://github.com/facebookresearch/detectron/blob/main/detectron/datasets/voc_dataset_evaluator.py): `detectron/datasets/voc_dataset_evaluator.py`

### Detection models

- [Model builder](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/model_builder.py): `detectron/modeling/model_builder.py`
- [Detector runtime](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/detector.py): `detectron/modeling/detector.py`
- [Backbones and FPN](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/FPN.py): `detectron/modeling/FPN.py`
- [ResNet backbone](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/ResNet.py): `detectron/modeling/ResNet.py`
- [Anchor generation](https://github.com/facebookresearch/detectron/blob/main/detectron/modeling/generate_anchors.py): `detectron/modeling/generate_anchors.py`
- [Detection heads](https://github.com/facebookresearch/detectron/tree/main/detectron/modeling): `detectron/modeling`
- [Proposal operations](https://github.com/facebookresearch/detectron/blob/main/detectron/ops/generate_proposals.py): `detectron/ops/generate_proposals.py`
- [FPN proposal routing](https://github.com/facebookresearch/detectron/blob/main/detectron/ops/collect_and_distribute_fpn_rpn_proposals.py): `detectron/ops/collect_and_distribute_fpn_rpn_proposals.py`

### Training and inference

- [Training CLI](https://github.com/facebookresearch/detectron/blob/main/tools/train_net.py): `tools/train_net.py`
- [Inference CLI](https://github.com/facebookresearch/detectron/blob/main/tools/infer.py): `tools/infer.py`
- [Configuration](https://github.com/facebookresearch/detectron/blob/main/detectron/core/config.py): `detectron/core/config.py`

### Core utilities

- [Tensor and geometry utilities](https://github.com/facebookresearch/detectron/tree/main/detectron/utils): `detectron/utils`

### Other components

- **Researcher**
- **Caffe2 framework**
- **Researcher results**

## Connections

- Researcher → Training CLI: starts training
- Researcher → Inference CLI: requests inference
- Training CLI → Model builder: builds model
- Inference CLI → Model builder: builds model
- Model builder → Configuration: reads settings (evidence: `detectron/modeling/model_builder.py`)
- COCO dataset → Dataset catalog: looks up metadata (evidence: `detectron/datasets/json_dataset.py`)
- COCO dataset → Region database: creates entries (evidence: `detectron/datasets/roidb.py`)
- Minibatch loader → Minibatch assembly: loads minibatches (evidence: `detectron/roi_data/loader.py`)
- Minibatch assembly → ROI targets: assembles targets (evidence: `detectron/roi_data/minibatch.py`)
- Model builder → Minibatch loader: uses loader (evidence: `detectron/modeling/model_builder.py`)
- Model builder → Minibatch assembly: uses minibatches (evidence: `detectron/modeling/model_builder.py`)
- Model builder → Detection heads: dispatches heads (evidence: `detectron/modeling/model_builder.py`)
- Model builder → Detector runtime: creates detector (evidence: `detectron/modeling/model_builder.py`)
- Model builder → Backbones and FPN: selects backbone (evidence: `detectron/modeling/model_builder.py`)
- Backbones and FPN → ResNet backbone: uses backbone (evidence: `detectron/modeling/FPN.py`)
- Backbones and FPN → Anchor generation: uses anchors (evidence: `detectron/modeling/FPN.py`)
- Detector runtime → ROI targets: uses ROI data (evidence: `detectron/modeling/detector.py`)
- Detector runtime → Proposal operations: generates proposals (evidence: `detectron/modeling/detector.py`)
- Detector runtime → FPN proposal routing: routes proposals (evidence: `detectron/modeling/detector.py`)
- FPN proposal routing → ROI targets: uses ROI targets (evidence: `detectron/ops/collect_and_distribute_fpn_rpn_proposals.py`)
- COCO dataset → Tensor and geometry utilities: uses geometry helpers (evidence: `detectron/datasets/json_dataset.py`)
- Training CLI → Caffe2 framework: runs on
- Inference CLI → Caffe2 framework: runs on
- Task evaluation → COCO evaluation: dispatches evaluator (evidence: `detectron/datasets/task_evaluation.py`)
- Task evaluation → Cityscapes evaluation: dispatches evaluator (evidence: `detectron/datasets/task_evaluation.py`)
- Task evaluation → VOC evaluation: dispatches evaluator (evidence: `detectron/datasets/task_evaluation.py`)
- Inference CLI → Task evaluation: evaluates predictions
- Inference CLI → Researcher results: returns detections
