# intellindust-ai-lab/deim architecture

> Architecture diagram of the GitHub repository intellindust-ai-lab/deim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/intellindust-ai-lab/deim
- Repository: https://github.com/intellindust-ai-lab/deim

## Overview

1. **What this repo is**
   - This is a PyTorch-based object detection training and deployment framework centered on **DEIM**, with re-implementations of **D-FINE** and **RT-DETRv2**.
   - The codebase is optimized for configuration-driven experiments on detection benchmarks such as **COCO**, **VOC**, **CrowdHuman**, and **Object365**.

2. **Top-level architecture**
   - The repo is split into a small number of major layers: **configs**, **engine**, **train entrypoint**, and **tools**.
   - `train.py` is the main orchestrator for training, evaluation, and fine-tuning.
   - `configs/` describes almost everything externally: dataset choice, backbone, detection head, optimizer, runtime, and model-size variants.

3. **Configuration system as the control plane**
   - `engine/core/` contains the YAML/config loading and workspace logic that merges base configs with experiment-specific overrides.
   - The config hierarchy in `configs/base`, `configs/dataset`, and model-family folders is the main mechanism for assembling a run.
   - This repo’s architecture is therefore not hard-coded around one model; it is assembled at runtime from YAML composition.

4. **Data ingestion pipeline**
   - `engine/data/` handles dataset creation, dataloading, batching, and transforms.
   - Dataset implementations live in `engine/data/dataset/`, with COCO and VOC as first-class supported formats and utilities for evaluation.
   - The pipeline goes from annotation files and image folders to batched tensors, with support for custom COCO-style datasets and category remapping.

5. **Augmentation and sample formatting**
   - `engine/data/transforms/` provides image/box transforms, including composition and mosaic-style augmentation.
   - The transform stack is part of the dataset config, so augmentation is selected per experiment rather than per model code path.
   - `engine/data/dataloader.py` and the collate functions shape samples into training batches compatible with variable-size detection inputs.

6. **Model subsystem**
   - `engine/deim/` contains the detection model families and their shared components.
   - Key pieces include the **hybrid encoder**, **deformable / matching utilities**, **denoising**, **decoders** for D-FINE and RT-DETRv2, **criterion**, **matcher**, and **postprocessor**.
   - This is the core architecture boundary: backbone features enter here, object queries/targets are matched here, and final boxes/scores are produced here.

7. **Backbone abstraction**
   - `engine/backbone/` provides reusable feature extractors, including project-specific backbones such as **HGNetv2**, **CSPDarknet**, and **CSPResNet**, plus adapters for **timm** and **torchvision** models.
   - Backbones are isolated behind common utilities, making the detection heads agnostic to the exact feature extractor.
   - This separation is important for diagramming because backbone choice is a configurable upstream branch feeding the shared detector stack.

8. **Training, loss, and optimization loop**
   - `engine/solver/` implements the training/evaluation engines and solver wrappers.
   - `engine/deim/deim_criterion.py` and `matcher.py` define the target assignment and loss computation, which are central to DETR-style training.
   - `engine/optim/` contains optimizer setup, learning-rate scheduling, warmup, AMP support, and EMA, all of which are configured centrally and consumed by the solver.

9. **Runtime and distributed execution**
   - The training entrypoint is designed for **multi-GPU distributed training via `torchrun`**.
   - `engine/misc/dist_utils.py` and logging/profiling helpers support distributed coordination, diagnostics, and performance inspection.
   - The README’s usage patterns show training, testing, and tuning as distinct execution modes over the same config-driven pipeline.

10. **Inference and post-training deployment**
   - `tools/deployment/` exports trained models to **ONNX** and can prepare them for downstream runtimes such as TensorRT.
   - `tools/inference/` provides inference paths for **PyTorch**, **ONNX Runtime**, **TensorRT**, and **OpenVINO**, so deployment is treated as a separate execution boundary from training.
   - `engine/deim/postprocessor.py` and box utilities define the final decoding stage that converts raw model outputs into usable detections.

11. **Benchmarking and visualization**
   - `tools/benchmark/` measures FLOPs, MACs, params, and TensorRT latency.
   - `tools/visualization/` and inference visualization scripts are for qualitative inspection of predictions, including FiftyOne integration.
   - These tools sit outside the training loop and consume exported or checkpointed models, making them downstream consumers of the same core detector.

12. **Dataset-specific utilities**
   - `tools/dataset/` contains conversion/remapping helpers, especially for Object365 preprocessing and category mapping.
   - This indicates the repo expects some datasets to be normalized into the COCO-style schema before training.
   - Dataset tooling is part of the data boundary, not the model boundary.

13. **External dependencies that shape the architecture**
   - The repo is built around **PyTorch**, with optional deployment/runtime dependencies on **ONNX**, **TensorRT**, **ONNX Runtime**, **OpenVINO**, and **FiftyOne**.
   - These are not incidental; they define separate execution targets for training, inference, benchmarking, and visualization.

14. **How the main data flow works**
   - Configs define the experiment.
   - The dataloader reads dataset annotations/images and applies transforms.
   - The backbone extracts multi-scale features.
   - The DEIM/D-FINE/RT-DETRv2 head encodes, decodes, and matches predictions to targets.
   - The criterion computes losses; the solver updates weights with optimizer, scheduler, AMP, and EMA.
   - Evaluation and postprocessing turn outputs into COCO-style metrics or deployable detections.

15. **Architecture summary for diagramming**
   - The clearest diagram is a pipeline with four major blocks: **config + runtime**, **data pipeline**, **model/training core**, and **deployment/tooling**.
   - The main boundary between reusable infrastructure and experiment logic is the YAML config layer.
   - The main boundary between generic detection infrastructure and model-specific logic is the `engine/deim` package.

Main entry points: [`engine/core`](https://github.com/intellindust-ai-lab/deim/tree/main/engine/core) (Config core), [`engine/deim`](https://github.com/intellindust-ai-lab/deim/tree/main/engine/deim) (DEIM core), [`train.py`](https://github.com/intellindust-ai-lab/deim/blob/main/train.py) (train.py), [`engine/data/dataloader.py`](https://github.com/intellindust-ai-lab/deim/blob/main/engine/data/dataloader.py) (Data loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_configs["Config plane"]
  node_train_py["train.py<br/>entrypoint<br/>[train.py]"]
  node_core_config["Config core<br/>yaml runtime"]
  node_runtime_cfg["Runtime cfg<br/>base settings<br/>[runtime.yml]"]
  node_base_cfgs["Base configs<br/>yaml composition"]
  node_dataset_cfgs["Dataset configs<br/>yaml datasets"]
  node_model_cfgs["Model configs<br/>yaml variants"]
  node_rtdetr_cfgs["RT-DETR configs<br/>yaml variants"]
end

subgraph group_grp_data["Data pipeline"]
  node_data_loader["Data loader<br/>batch pipeline<br/>[dataloader.py]"]
  node_datasets[("Datasets<br/>dataset adapters")]
  node_transforms["Transforms<br/>augmentation stack"]
end

subgraph group_grp_model["Detection core"]
  node_backbones["Backbones<br/>feature extractors"]
  node_deim_core{{"DEIM core<br/>detector family"}}
  node_encoder["Hybrid encoder<br/>feature fusion<br/>[hybrid_encoder.py]"]
  node_decoders["Decoders<br/>[dfine_decoder.py]"]
  node_matcher_loss["Matcher + loss<br/>assignment and criterion<br/>[matcher.py]"]
  node_postproc["Postprocess<br/>box decoding<br/>[postprocessor.py]"]
  node_optim_stack["Optim stack<br/>optimizer control"]
  node_solver["Solver<br/>train/eval engine"]
  node_dist_utils["Distributed utils<br/>distributed runtime<br/>[dist_utils.py]"]
end

subgraph group_grp_tools["Deployment tools"]
  node_export_tools["Export tools<br/>deployment"]
  node_inference_tools["Inference tools<br/>runtime targets"]
  node_benchmark_tools["Benchmark tools<br/>performance tools"]
  node_viz_tools["Visualization<br/>inspection tools"]
  node_dataset_tools["Dataset tools<br/>preprocessing"]
end

node_train_py -->|"loads"| node_core_config
node_core_config -->|"merges"| node_runtime_cfg
node_core_config -->|"composes"| node_base_cfgs
node_core_config -->|"selects"| node_dataset_cfgs
node_core_config -->|"selects"| node_model_cfgs
node_core_config -->|"selects"| node_rtdetr_cfgs
node_train_py -->|"builds"| node_data_loader
node_data_loader -->|"reads"| node_datasets
node_data_loader -->|"applies"| node_transforms
node_data_loader -->|"feeds"| node_solver
node_train_py -->|"instantiates"| node_backbones
node_backbones -->|"features"| node_deim_core
node_deim_core -->|"contains"| node_encoder
node_encoder -->|"passes"| node_decoders
node_decoders -->|"trains with"| node_matcher_loss
node_matcher_loss -->|"optimizes"| node_solver
node_solver -->|"uses"| node_optim_stack
node_solver -->|"coordinates"| node_dist_utils
node_deim_core -->|"outputs"| node_postproc
node_train_py -->|"invokes"| node_export_tools
node_export_tools -->|"targets"| node_inference_tools
node_deim_core -->|"measured by"| node_benchmark_tools
node_deim_core -->|"visualized by"| node_viz_tools
node_dataset_tools -->|"prepares"| node_datasets

click node_train_py "https://github.com/intellindust-ai-lab/deim/blob/main/train.py"
click node_core_config "https://github.com/intellindust-ai-lab/deim/tree/main/engine/core"
click node_runtime_cfg "https://github.com/intellindust-ai-lab/deim/blob/main/configs/runtime.yml"
click node_base_cfgs "https://github.com/intellindust-ai-lab/deim/tree/main/configs/base"
click node_dataset_cfgs "https://github.com/intellindust-ai-lab/deim/tree/main/configs/dataset"
click node_model_cfgs "https://github.com/intellindust-ai-lab/deim/tree/main/configs/deim_dfine"
click node_rtdetr_cfgs "https://github.com/intellindust-ai-lab/deim/tree/main/configs/deim_rtdetrv2"
click node_data_loader "https://github.com/intellindust-ai-lab/deim/blob/main/engine/data/dataloader.py"
click node_datasets "https://github.com/intellindust-ai-lab/deim/tree/main/engine/data/dataset"
click node_transforms "https://github.com/intellindust-ai-lab/deim/tree/main/engine/data/transforms"
click node_backbones "https://github.com/intellindust-ai-lab/deim/tree/main/engine/backbone"
click node_deim_core "https://github.com/intellindust-ai-lab/deim/tree/main/engine/deim"
click node_encoder "https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/hybrid_encoder.py"
click node_decoders "https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/dfine_decoder.py"
click node_matcher_loss "https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/matcher.py"
click node_postproc "https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/postprocessor.py"
click node_optim_stack "https://github.com/intellindust-ai-lab/deim/tree/main/engine/optim"
click node_solver "https://github.com/intellindust-ai-lab/deim/tree/main/engine/solver"
click node_dist_utils "https://github.com/intellindust-ai-lab/deim/blob/main/engine/misc/dist_utils.py"
click node_export_tools "https://github.com/intellindust-ai-lab/deim/tree/main/tools/deployment"
click node_inference_tools "https://github.com/intellindust-ai-lab/deim/tree/main/tools/inference"
click node_benchmark_tools "https://github.com/intellindust-ai-lab/deim/tree/main/tools/benchmark"
click node_viz_tools "https://github.com/intellindust-ai-lab/deim/tree/main/tools/visualization"
click node_dataset_tools "https://github.com/intellindust-ai-lab/deim/tree/main/tools/dataset"

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_py,node_core_config,node_runtime_cfg,node_base_cfgs,node_dataset_cfgs,node_model_cfgs,node_rtdetr_cfgs toneBlue
class node_data_loader,node_datasets,node_transforms toneAmber
class node_backbones,node_deim_core,node_encoder,node_decoders,node_matcher_loss,node_postproc,node_optim_stack,node_solver,node_dist_utils toneMint
class node_export_tools,node_inference_tools,node_benchmark_tools,node_viz_tools,node_dataset_tools toneRose
```

## Components

### Config plane

YAML composition and runtime setup for experiments

- [train.py](https://github.com/intellindust-ai-lab/deim/blob/main/train.py): entrypoint · Main training, evaluation, and fine-tuning driver · `train.py`
- [Config core](https://github.com/intellindust-ai-lab/deim/tree/main/engine/core): yaml runtime · Loads, merges, and manages experiment configuration · `engine/core`
- [Runtime cfg](https://github.com/intellindust-ai-lab/deim/blob/main/configs/runtime.yml): base settings · Shared runtime, workspace, and default execution settings · `configs/runtime.yml`
- [Base configs](https://github.com/intellindust-ai-lab/deim/tree/main/configs/base): yaml composition · Reusable model, optimizer, and dataloader building blocks · `configs/base`
- [Dataset configs](https://github.com/intellindust-ai-lab/deim/tree/main/configs/dataset): yaml datasets · Dataset-specific experiment presets and annotation schemas · `configs/dataset`
- [Model configs](https://github.com/intellindust-ai-lab/deim/tree/main/configs/deim_dfine): yaml variants · DEIM, D-FINE, and RT-DETRv2 experiment definitions · `configs/deim_dfine`
- [RT-DETR configs](https://github.com/intellindust-ai-lab/deim/tree/main/configs/deim_rtdetrv2): yaml variants · RT-DETRv2 and DEIM-RT-DETRv2 experiment definitions · `configs/deim_rtdetrv2`

### Data pipeline

Dataset loading, transforms, batching, and evaluation

- [Data loader](https://github.com/intellindust-ai-lab/deim/blob/main/engine/data/dataloader.py): batch pipeline · Builds dataloaders and collates variable-size detection samples · `engine/data/dataloader.py`
- [Datasets](https://github.com/intellindust-ai-lab/deim/tree/main/engine/data/dataset): dataset adapters · COCO, VOC, and custom dataset readers plus evaluation helpers · `engine/data/dataset`
- [Transforms](https://github.com/intellindust-ai-lab/deim/tree/main/engine/data/transforms): augmentation stack · Image, box, and mosaic-style augmentation composition · `engine/data/transforms`

### Detection core

Backbones, DEIM family, matching, losses, and optimization

- [Backbones](https://github.com/intellindust-ai-lab/deim/tree/main/engine/backbone): feature extractors · HGNetv2, CSPDarknet, CSPResNet, and external backbone adapters · `engine/backbone`
- [DEIM core](https://github.com/intellindust-ai-lab/deim/tree/main/engine/deim): detector family · Shared detector stack for DEIM, D-FINE, and RT-DETRv2 · `engine/deim`
- [Hybrid encoder](https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/hybrid_encoder.py): feature fusion · Multiscale feature aggregation before decoding · `engine/deim/hybrid_encoder.py`
- [Decoders](https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/dfine_decoder.py): query decoders · D-FINE and RT-DETRv2 decoding heads · `engine/deim/dfine_decoder.py`
- [Matcher + loss](https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/matcher.py): assignment and criterion · Target matching and DETR-style loss computation · `engine/deim/matcher.py`
- [Postprocess](https://github.com/intellindust-ai-lab/deim/blob/main/engine/deim/postprocessor.py): box decoding · Final box and score decoding for evaluation and inference · `engine/deim/postprocessor.py`
- [Optim stack](https://github.com/intellindust-ai-lab/deim/tree/main/engine/optim): optimizer control · Optimizer, LR schedule, warmup, AMP, and EMA utilities · `engine/optim`
- [Solver](https://github.com/intellindust-ai-lab/deim/tree/main/engine/solver): train/eval engine · Orchestrates training and evaluation loops · `engine/solver`
- [Distributed utils](https://github.com/intellindust-ai-lab/deim/blob/main/engine/misc/dist_utils.py): distributed runtime · Multi-GPU coordination, logging, and profiling support · `engine/misc/dist_utils.py`

### Deployment tools

Export, inference, benchmarking, and visualization

- [Export tools](https://github.com/intellindust-ai-lab/deim/tree/main/tools/deployment): deployment · ONNX and export utilities for downstream runtimes · `tools/deployment`
- [Inference tools](https://github.com/intellindust-ai-lab/deim/tree/main/tools/inference): runtime targets · PyTorch, ONNX Runtime, TensorRT, and OpenVINO inference · `tools/inference`
- [Benchmark tools](https://github.com/intellindust-ai-lab/deim/tree/main/tools/benchmark): performance tools · FLOPs, params, and latency measurement utilities · `tools/benchmark`
- [Visualization](https://github.com/intellindust-ai-lab/deim/tree/main/tools/visualization): inspection tools · Prediction visualization and FiftyOne-based inspection · `tools/visualization`
- [Dataset tools](https://github.com/intellindust-ai-lab/deim/tree/main/tools/dataset): preprocessing · Object365 remapping and resizing helpers · `tools/dataset`

## Connections

- train.py → Config core: loads · Entry point initializes experiment configuration
- Config core → Runtime cfg: merges · Applies shared runtime settings
- Config core → Base configs: composes · Builds runs from reusable base YAMLs
- Config core → Dataset configs: selects · Chooses dataset-specific pipeline settings
- Config core → Model configs: selects · Chooses DEIM/D-FINE variants
- Config core → RT-DETR configs: selects · Chooses RT-DETRv2 variants
- train.py → Data loader: builds · Constructs the dataloading pipeline
- Data loader → Datasets: reads · Loads images and annotations from dataset adapters
- Data loader → Transforms: applies · Runs augmentation and formatting stack
- Data loader → Solver: feeds · Produces batches consumed by the engine
- train.py → Backbones: instantiates · Creates the configured feature extractor
- Backbones → DEIM core: features · Backbone features enter detector core
- DEIM core → Hybrid encoder: contains · Aggregates multiscale features
- Hybrid encoder → Decoders: passes · Encoded features are decoded into predictions
- Decoders → Matcher + loss: trains with · Predictions are matched to targets for loss
- Matcher + loss → Solver: optimizes · Criterion drives parameter updates through solver
- Solver → Optim stack: uses · Solver consumes optimizer and schedule policy
- Solver → Distributed utils: coordinates · Distributed execution and diagnostics
- DEIM core → Postprocess: outputs · Raw detector outputs are decoded for evaluation or inference
- train.py → Export tools: invokes · Training artifacts can be exported for deployment
- Export tools → Inference tools: targets · Exported models are consumed by inference runtimes
- DEIM core → Benchmark tools: measured by · Core models are profiled for FLOPs and latency
- DEIM core → Visualization: visualized by · Predictions are inspected qualitatively
- Dataset tools → Datasets: prepares · Dataset preprocessing normalizes data into training format
