# rangilyu/nanodet architecture

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

- Interactive diagram: https://gitdiagram.com/rangilyu/nanodet
- Repository: https://github.com/rangilyu/nanodet

## Overview

NanoDet-Plus is a lightweight anchor-free object detector with a Python/PyTorch training and inference package and documented deployment demos. The main runtime path loads a configured model and checkpoint, preprocesses an image, runs detection, then visualizes results; training builds the model and computes losses through a task runner. The graph also preserves the documented COCO evaluation and ncnn, MNN, OpenVINO, LibTorch, and Android deployment branches. Some subsystem links rely on README or SOURCE INDEX references because their implementation excerpts were not provided.

Main entry points: [`tools/inference.py`](https://github.com/rangilyu/nanodet/blob/main/tools/inference.py) (Inference predictor), [`nanodet/trainer/task.py`](https://github.com/rangilyu/nanodet/blob/main/nanodet/trainer/task.py) (Training task), [`nanodet/model/arch/nanodet_plus.py`](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/arch/nanodet_plus.py) (Detector architecture), [`nanodet/model/head/nanodet_plus_head.py`](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/head/nanodet_plus_head.py) (Detection head)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_datasets[("Detection datasets")]
  node_transforms["Image transforms<br/>[pipeline.py]"]
  node_batch["Batch processing<br/>[batch_process.py]"]
end

subgraph group_model["Detection model"]
  node_architecture["Detector architecture<br/>[nanodet_plus.py]"]
  node_backbones["Backbones"]
  node_feature_pyramid["Feature pyramid<br/>[ghost_pan.py]"]
  node_head["Detection head"]
  node_assigner["Label assigners<br/>[atss_assigner.py]"]
  node_losses["Detection losses<br/>[gfocal_loss.py]"]
  node_conv["Model building blocks<br/>[conv.py]"]
end

subgraph group_runtime["Training and inference"]
  node_training["Training task<br/>[task.py]"]
  node_optimizer["Optimizer builder<br/>[builder.py]"]
  node_evaluator["COCO evaluator<br/>[coco_detection.py]"]
  node_predictor["Inference predictor<br/>[inference.py]"]
  node_utilities["Model utilities<br/>[check_point.py]"]
  node_visualizer["Result visualization<br/>[visualization.py]"]
end

subgraph group_deploy["Deployment demos"]
  node_ncnn["ncnn C++ demo<br/>[main.cpp]"]
  node_mnn["MNN C++ demo<br/>[main.cpp]"]
  node_openvino["OpenVINO demo<br/>[main.cpp]"]
  node_libtorch["LibTorch demo<br/>[main.cpp]"]
  node_android["Android ncnn app<br/>[MainActivity.java]"]
  node_mobile_native["Android native detector<br/>[NanoDet.cpp]"]
end

node_user(("User"))

node_user -->|"requests inference"| node_predictor
node_predictor -->|"builds model"| node_architecture
node_predictor -->|"loads weights"| node_utilities
node_predictor -->|"preprocesses image"| node_transforms
node_predictor -->|"renders detections"| node_visualizer
node_transforms -.->|"transforms metadata"| node_datasets
node_transforms -.->|"prepares inputs"| node_batch
node_architecture -.->|"uses backbone"| node_backbones
node_architecture -.->|"uses pyramid"| node_feature_pyramid
node_architecture -.->|"uses head"| node_head
node_head -->|"assigns labels"| node_assigner
node_head -->|"computes losses"| node_losses
node_head -->|"uses layers"| node_conv
node_training -->|"builds model"| node_architecture
node_training -->|"stacks images"| node_batch
node_training -.->|"builds optimizer"| node_optimizer
node_training -->|"evaluates results"| node_evaluator
node_user -.->|"trains detector"| node_training
node_user -->|"runs demo"| node_ncnn
node_user -->|"runs demo"| node_mnn
node_user -->|"runs demo"| node_openvino
node_user -.->|"runs demo"| node_libtorch
node_user -->|"uses mobile app"| node_android
node_android -.->|"invokes detector"| node_mobile_native

click node_datasets "https://github.com/rangilyu/nanodet/tree/main/nanodet/data/dataset"
click node_transforms "https://github.com/rangilyu/nanodet/blob/main/nanodet/data/transform/pipeline.py"
click node_batch "https://github.com/rangilyu/nanodet/blob/main/nanodet/data/batch_process.py"
click node_architecture "https://github.com/rangilyu/nanodet/blob/main/nanodet/model/arch/nanodet_plus.py"
click node_backbones "https://github.com/rangilyu/nanodet/tree/main/nanodet/model/backbone"
click node_feature_pyramid "https://github.com/rangilyu/nanodet/blob/main/nanodet/model/fpn/ghost_pan.py"
click node_head "https://github.com/rangilyu/nanodet/blob/main/nanodet/model/head/nanodet_plus_head.py"
click node_assigner "https://github.com/rangilyu/nanodet/blob/main/nanodet/model/head/assigner/atss_assigner.py"
click node_losses "https://github.com/rangilyu/nanodet/blob/main/nanodet/model/loss/gfocal_loss.py"
click node_conv "https://github.com/rangilyu/nanodet/blob/main/nanodet/model/module/conv.py"
click node_training "https://github.com/rangilyu/nanodet/blob/main/nanodet/trainer/task.py"
click node_optimizer "https://github.com/rangilyu/nanodet/blob/main/nanodet/optim/builder.py"
click node_evaluator "https://github.com/rangilyu/nanodet/blob/main/nanodet/evaluator/coco_detection.py"
click node_predictor "https://github.com/rangilyu/nanodet/blob/main/tools/inference.py"
click node_utilities "https://github.com/rangilyu/nanodet/blob/main/nanodet/util/check_point.py"
click node_visualizer "https://github.com/rangilyu/nanodet/blob/main/nanodet/util/visualization.py"
click node_ncnn "https://github.com/rangilyu/nanodet/blob/main/demo_ncnn/main.cpp"
click node_mnn "https://github.com/rangilyu/nanodet/blob/main/demo_mnn/main.cpp"
click node_openvino "https://github.com/rangilyu/nanodet/blob/main/demo_openvino/main.cpp"
click node_libtorch "https://github.com/rangilyu/nanodet/blob/main/demo_libtorch/main.cpp"
click node_android "https://github.com/rangilyu/nanodet/blob/main/demo_android_ncnn/app/src/main/java/com/rangi/nanodet/MainActivity.java"
click node_mobile_native "https://github.com/rangilyu/nanodet/blob/main/demo_android_ncnn/app/src/main/cpp/NanoDet.cpp"

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_datasets,node_transforms,node_batch,node_user toneBlue
class node_architecture,node_backbones,node_feature_pyramid,node_head,node_assigner,node_losses,node_conv toneAmber
class node_training,node_optimizer,node_evaluator,node_predictor,node_utilities,node_visualizer toneMint
class node_ncnn,node_mnn,node_openvino,node_libtorch,node_android,node_mobile_native toneRose
```

## Components

### Data preparation

- [Detection datasets](https://github.com/rangilyu/nanodet/tree/main/nanodet/data/dataset): `nanodet/data/dataset`
- [Image transforms](https://github.com/rangilyu/nanodet/blob/main/nanodet/data/transform/pipeline.py): `nanodet/data/transform/pipeline.py`
- [Batch processing](https://github.com/rangilyu/nanodet/blob/main/nanodet/data/batch_process.py): `nanodet/data/batch_process.py`

### Detection model

- [Detector architecture](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/arch/nanodet_plus.py): `nanodet/model/arch/nanodet_plus.py`
- [Backbones](https://github.com/rangilyu/nanodet/tree/main/nanodet/model/backbone): `nanodet/model/backbone`
- [Feature pyramid](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/fpn/ghost_pan.py): `nanodet/model/fpn/ghost_pan.py`
- [Detection head](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/head/nanodet_plus_head.py): `nanodet/model/head/nanodet_plus_head.py`
- [Label assigners](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/head/assigner/atss_assigner.py): `nanodet/model/head/assigner/atss_assigner.py`
- [Detection losses](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/loss/gfocal_loss.py): `nanodet/model/loss/gfocal_loss.py`
- [Model building blocks](https://github.com/rangilyu/nanodet/blob/main/nanodet/model/module/conv.py): `nanodet/model/module/conv.py`

### Training and inference

- [Training task](https://github.com/rangilyu/nanodet/blob/main/nanodet/trainer/task.py): `nanodet/trainer/task.py`
- [Optimizer builder](https://github.com/rangilyu/nanodet/blob/main/nanodet/optim/builder.py): `nanodet/optim/builder.py`
- [COCO evaluator](https://github.com/rangilyu/nanodet/blob/main/nanodet/evaluator/coco_detection.py): `nanodet/evaluator/coco_detection.py`
- [Inference predictor](https://github.com/rangilyu/nanodet/blob/main/tools/inference.py): `tools/inference.py`
- [Model utilities](https://github.com/rangilyu/nanodet/blob/main/nanodet/util/check_point.py): `nanodet/util/check_point.py`
- [Result visualization](https://github.com/rangilyu/nanodet/blob/main/nanodet/util/visualization.py): `nanodet/util/visualization.py`

### Deployment demos

- [ncnn C++ demo](https://github.com/rangilyu/nanodet/blob/main/demo_ncnn/main.cpp): `demo_ncnn/main.cpp`
- [MNN C++ demo](https://github.com/rangilyu/nanodet/blob/main/demo_mnn/main.cpp): `demo_mnn/main.cpp`
- [OpenVINO demo](https://github.com/rangilyu/nanodet/blob/main/demo_openvino/main.cpp): `demo_openvino/main.cpp`
- [LibTorch demo](https://github.com/rangilyu/nanodet/blob/main/demo_libtorch/main.cpp): `demo_libtorch/main.cpp`
- [Android ncnn app](https://github.com/rangilyu/nanodet/blob/main/demo_android_ncnn/app/src/main/java/com/rangi/nanodet/MainActivity.java): `demo_android_ncnn/app/src/main/java/com/rangi/nanodet/MainActivity.java`
- [Android native detector](https://github.com/rangilyu/nanodet/blob/main/demo_android_ncnn/app/src/main/cpp/NanoDet.cpp): `demo_android_ncnn/app/src/main/cpp/NanoDet.cpp`

### Other components

- **User**

## Connections

- User → Inference predictor: requests inference (evidence: `tools/inference.py`)
- Inference predictor → Detector architecture: builds model (evidence: `tools/inference.py`)
- Inference predictor → Model utilities: loads weights (evidence: `tools/inference.py`)
- Inference predictor → Image transforms: preprocesses image (evidence: `tools/inference.py`)
- Inference predictor → Result visualization: renders detections (evidence: `tools/inference.py`)
- Image transforms → Detection datasets: transforms metadata
- Image transforms → Batch processing: prepares inputs
- Detector architecture → Backbones: uses backbone
- Detector architecture → Feature pyramid: uses pyramid
- Detector architecture → Detection head: uses head
- Detection head → Label assigners: assigns labels
- Detection head → Detection losses: computes losses
- Detection head → Model building blocks: uses layers
- Training task → Detector architecture: builds model (evidence: `nanodet/trainer/task.py`)
- Training task → Batch processing: stacks images (evidence: `nanodet/trainer/task.py`)
- Training task → Optimizer builder: builds optimizer
- Training task → COCO evaluator: evaluates results (evidence: `nanodet/trainer/task.py`)
- User → Training task: trains detector (evidence: `README.md`)
- User → ncnn C++ demo: runs demo (evidence: `README.md`)
- User → MNN C++ demo: runs demo (evidence: `README.md`)
- User → OpenVINO demo: runs demo (evidence: `README.md`)
- User → LibTorch demo: runs demo (evidence: `README.md`)
- User → Android ncnn app: uses mobile app (evidence: `README.md`)
- Android ncnn app → Android native detector: invokes detector
