# tianzhi0549/fcos architecture

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

- Interactive diagram: https://gitdiagram.com/tianzhi0549/fcos
- Repository: https://github.com/tianzhi0549/fcos

## Overview

FCOS is a PyTorch, anchor-free object-detection implementation. Its principal workflow takes images through a configured detector to bounding-box predictions; training builds datasets and a model, then optimizes and checkpoints it, while evaluation aggregates predictions and evaluates datasets. The graph also includes the RetinaNet alternative, ROI heads, ONNX export, and shared box/layer utilities. Some subsystem links rely on the README or SOURCE INDEX references; unsampled implementation details are not inferred as direct calls.

Main entry points: [`fcos_core/modeling/detector/generalized_rcnn.py`](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/detector/generalized_rcnn.py) (Detector assembly), [`tools/train_net.py`](https://github.com/tianzhi0549/fcos/blob/master/tools/train_net.py) (Training command), [`fcos/fcos.py`](https://github.com/tianzhi0549/fcos/blob/master/fcos/fcos.py) (Image detector API), [`fcos_core/modeling/rpn/fcos/inference.py`](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/fcos/inference.py) (FCOS postprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry points"]
  node_train_cli["Training command<br/>[train_net.py]"]
  node_image_api["Image detector API<br/>[fcos.py]"]
  node_onnx["ONNX export"]
end

subgraph group_training["Training data and loop"]
  node_dataset["COCO and VOC data"]
  node_data_loader["Data loader<br/>[build.py]"]
  node_transforms["Image transforms"]
  node_trainer["Training loop<br/>[trainer.py]"]
  node_solver["Optimizer scheduler<br/>[build.py]"]
end

subgraph group_detection["Detection model"]
  node_model_builder["Detector assembly"]
  node_backbone["Backbone and FPN"]
  node_fcos_head["FCOS prediction head<br/>[fcos.py]"]
  node_retinanet["RetinaNet head<br/>[retinanet.py]"]
  node_roi_heads["Box mask keypoints"]
end

subgraph group_results["Inference and results"]
  node_postprocess["FCOS postprocessing<br/>[inference.py]"]
  node_inference["Inference evaluator<br/>[inference.py]"]
  node_evaluation["Dataset evaluation"]
end

subgraph group_support["Shared runtime support"]
  node_config["Model configuration<br/>[defaults.py]"]
  node_box_coder["Box encoding<br/>[box_coder.py]"]
  node_boxlist["Box data structure<br/>[bounding_box.py]"]
  node_box_ops["Box filtering NMS<br/>[boxlist_ops.py]"]
  node_layers["Tensor and vision ops<br/>[misc.py]"]
  node_checkpoint["Checkpoint loading<br/>[checkpoint.py]"]
  node_utilities["Runtime utilities"]
end

node_user(("Image user"))

node_user -->|"submits image"| node_image_api
node_image_api -->|"loads settings"| node_config
node_image_api -->|"builds detector"| node_model_builder
node_image_api -->|"loads weights"| node_checkpoint
node_train_cli -->|"reads settings"| node_config
node_train_cli -->|"builds detector"| node_model_builder
node_train_cli -->|"builds batches"| node_data_loader
node_train_cli -->|"builds optimizer"| node_solver
node_train_cli -->|"starts training"| node_trainer
node_data_loader -->|"constructs datasets"| node_dataset
node_data_loader -->|"builds transforms"| node_transforms
node_model_builder -.->|"assembles model"| node_backbone
node_model_builder -.->|"assembles model"| node_fcos_head
node_model_builder -.->|"supports alternative"| node_retinanet
node_model_builder -.->|"supports heads"| node_roi_heads
node_fcos_head -.->|"produces predictions"| node_postprocess
node_postprocess -->|"decodes boxes"| node_box_coder
node_postprocess -->|"creates detections"| node_boxlist
node_postprocess -->|"filters boxes"| node_box_ops
node_box_ops -->|"operates on boxes"| node_boxlist
node_box_ops -->|"uses NMS ops"| node_layers
node_inference -->|"evaluates results"| node_evaluation
node_inference -->|"gathers predictions"| node_utilities
node_onnx -->|"builds detector"| node_model_builder
node_onnx -->|"loads weights"| node_checkpoint
node_onnx -->|"imports evaluator"| node_inference

click node_train_cli "https://github.com/tianzhi0549/fcos/blob/master/tools/train_net.py"
click node_image_api "https://github.com/tianzhi0549/fcos/blob/master/fcos/fcos.py"
click node_config "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/config/defaults.py"
click node_dataset "https://github.com/tianzhi0549/fcos/tree/master/fcos_core/data/datasets"
click node_data_loader "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/data/build.py"
click node_transforms "https://github.com/tianzhi0549/fcos/tree/master/fcos_core/data/transforms"
click node_trainer "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/engine/trainer.py"
click node_solver "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/solver/build.py"
click node_model_builder "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/detector/generalized_rcnn.py"
click node_backbone "https://github.com/tianzhi0549/fcos/tree/master/fcos_core/modeling/backbone"
click node_fcos_head "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/fcos/fcos.py"
click node_retinanet "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/retinanet/retinanet.py"
click node_roi_heads "https://github.com/tianzhi0549/fcos/tree/master/fcos_core/modeling/roi_heads"
click node_box_coder "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/box_coder.py"
click node_boxlist "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/structures/bounding_box.py"
click node_box_ops "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/structures/boxlist_ops.py"
click node_layers "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/layers/misc.py"
click node_postprocess "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/fcos/inference.py"
click node_inference "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/engine/inference.py"
click node_evaluation "https://github.com/tianzhi0549/fcos/tree/master/fcos_core/data/datasets/evaluation"
click node_checkpoint "https://github.com/tianzhi0549/fcos/blob/master/fcos_core/utils/checkpoint.py"
click node_onnx "https://github.com/tianzhi0549/fcos/blob/master/onnx/export_model_to_onnx.py"
click node_utilities "https://github.com/tianzhi0549/fcos/tree/master/fcos_core/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_train_cli,node_image_api,node_onnx,node_user toneBlue
class node_dataset,node_data_loader,node_transforms,node_trainer,node_solver toneAmber
class node_model_builder,node_backbone,node_fcos_head,node_retinanet,node_roi_heads toneMint
class node_postprocess,node_inference,node_evaluation toneRose
class node_config,node_box_coder,node_boxlist,node_box_ops,node_layers,node_checkpoint,node_utilities toneIndigo
```

## Components

### User entry points

- [Training command](https://github.com/tianzhi0549/fcos/blob/master/tools/train_net.py): `tools/train_net.py`
- [Image detector API](https://github.com/tianzhi0549/fcos/blob/master/fcos/fcos.py): `fcos/fcos.py`
- [ONNX export](https://github.com/tianzhi0549/fcos/blob/master/onnx/export_model_to_onnx.py): `onnx/export_model_to_onnx.py`

### Training data and loop

- [COCO and VOC data](https://github.com/tianzhi0549/fcos/tree/master/fcos_core/data/datasets): `fcos_core/data/datasets`
- [Data loader](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/data/build.py): `fcos_core/data/build.py`
- [Image transforms](https://github.com/tianzhi0549/fcos/tree/master/fcos_core/data/transforms): `fcos_core/data/transforms`
- [Training loop](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/engine/trainer.py): `fcos_core/engine/trainer.py`
- [Optimizer scheduler](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/solver/build.py): `fcos_core/solver/build.py`

### Detection model

- [Detector assembly](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/detector/generalized_rcnn.py): `fcos_core/modeling/detector/generalized_rcnn.py`
- [Backbone and FPN](https://github.com/tianzhi0549/fcos/tree/master/fcos_core/modeling/backbone): `fcos_core/modeling/backbone`
- [FCOS prediction head](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/fcos/fcos.py): `fcos_core/modeling/rpn/fcos/fcos.py`
- [RetinaNet head](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/retinanet/retinanet.py): `fcos_core/modeling/rpn/retinanet/retinanet.py`
- [Box mask keypoints](https://github.com/tianzhi0549/fcos/tree/master/fcos_core/modeling/roi_heads): `fcos_core/modeling/roi_heads`

### Inference and results

- [FCOS postprocessing](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/rpn/fcos/inference.py): `fcos_core/modeling/rpn/fcos/inference.py`
- [Inference evaluator](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/engine/inference.py): `fcos_core/engine/inference.py`
- [Dataset evaluation](https://github.com/tianzhi0549/fcos/tree/master/fcos_core/data/datasets/evaluation): `fcos_core/data/datasets/evaluation`

### Shared runtime support

- [Model configuration](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/config/defaults.py): `fcos_core/config/defaults.py`
- [Box encoding](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/modeling/box_coder.py): `fcos_core/modeling/box_coder.py`
- [Box data structure](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/structures/bounding_box.py): `fcos_core/structures/bounding_box.py`
- [Box filtering NMS](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/structures/boxlist_ops.py): `fcos_core/structures/boxlist_ops.py`
- [Tensor and vision ops](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/layers/misc.py): `fcos_core/layers/misc.py`
- [Checkpoint loading](https://github.com/tianzhi0549/fcos/blob/master/fcos_core/utils/checkpoint.py): `fcos_core/utils/checkpoint.py`
- [Runtime utilities](https://github.com/tianzhi0549/fcos/tree/master/fcos_core/utils): `fcos_core/utils`

### Other components

- **Image user**

## Connections

- Image user → Image detector API: submits image (evidence: `README.md`)
- Image detector API → Model configuration: loads settings (evidence: `fcos/fcos.py`)
- Image detector API → Detector assembly: builds detector (evidence: `fcos/fcos.py`)
- Image detector API → Checkpoint loading: loads weights (evidence: `fcos/fcos.py`)
- Training command → Model configuration: reads settings (evidence: `tools/train_net.py`)
- Training command → Detector assembly: builds detector (evidence: `tools/train_net.py`)
- Training command → Data loader: builds batches (evidence: `tools/train_net.py`)
- Training command → Optimizer scheduler: builds optimizer (evidence: `tools/train_net.py`)
- Training command → Training loop: starts training (evidence: `tools/train_net.py`)
- Data loader → COCO and VOC data: constructs datasets (evidence: `fcos_core/data/build.py`)
- Data loader → Image transforms: builds transforms (evidence: `fcos_core/data/build.py`)
- Detector assembly → Backbone and FPN: assembles model
- Detector assembly → FCOS prediction head: assembles model
- Detector assembly → RetinaNet head: supports alternative
- Detector assembly → Box mask keypoints: supports heads
- FCOS prediction head → FCOS postprocessing: produces predictions
- FCOS postprocessing → Box encoding: decodes boxes (evidence: `fcos_core/modeling/rpn/fcos/inference.py`)
- FCOS postprocessing → Box data structure: creates detections (evidence: `fcos_core/modeling/rpn/fcos/inference.py`)
- FCOS postprocessing → Box filtering NMS: filters boxes (evidence: `fcos_core/modeling/rpn/fcos/inference.py`)
- Box filtering NMS → Box data structure: operates on boxes (evidence: `fcos_core/structures/boxlist_ops.py`)
- Box filtering NMS → Tensor and vision ops: uses NMS ops (evidence: `fcos_core/structures/boxlist_ops.py`)
- Inference evaluator → Dataset evaluation: evaluates results (evidence: `fcos_core/engine/inference.py`)
- Inference evaluator → Runtime utilities: gathers predictions (evidence: `fcos_core/engine/inference.py`)
- ONNX export → Detector assembly: builds detector (evidence: `onnx/export_model_to_onnx.py`)
- ONNX export → Checkpoint loading: loads weights (evidence: `onnx/export_model_to_onnx.py`)
- ONNX export → Inference evaluator: imports evaluator (evidence: `onnx/export_model_to_onnx.py`)
