How intellindust-ai-lab/deim works
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: core Config core · deim DEIM core · train.py train.py · dataloader.py Data loader
Components 24
Config plane
YAML composition and runtime setup for experiments
- train.py · Main training, evaluation, and fine-tuning driver
train.py - Config core · Loads, merges, and manages experiment configuration
engine/core - Runtime cfg · Shared runtime, workspace, and default execution settings
configs/runtime.yml - Base configs · Reusable model, optimizer, and dataloader building blocks
configs/base - Dataset configs · Dataset-specific experiment presets and annotation schemas
configs/dataset - Model configs · DEIM, D-FINE, and RT-DETRv2 experiment definitions
configs/deim_dfine - RT-DETR configs · RT-DETRv2 and DEIM-RT-DETRv2 experiment definitions
configs/deim_rtdetrv2
Data pipeline
Dataset loading, transforms, batching, and evaluation
- Data loader · Builds dataloaders and collates variable-size detection samples
engine/data/dataloader.py - Datasets · COCO, VOC, and custom dataset readers plus evaluation helpers
engine/data/dataset - Transforms · Image, box, and mosaic-style augmentation composition
engine/data/transforms
Detection core
Backbones, DEIM family, matching, losses, and optimization
- Backbones · HGNetv2, CSPDarknet, CSPResNet, and external backbone adapters
engine/backbone - DEIM core · Shared detector stack for DEIM, D-FINE, and RT-DETRv2
engine/deim - Hybrid encoder · Multiscale feature aggregation before decoding
engine/deim/hybrid_encoder.py - Decoders · D-FINE and RT-DETRv2 decoding heads
engine/deim/dfine_decoder.py - Matcher + loss · Target matching and DETR-style loss computation
engine/deim/matcher.py - Postprocess · Final box and score decoding for evaluation and inference
engine/deim/postprocessor.py - Optim stack · Optimizer, LR schedule, warmup, AMP, and EMA utilities
engine/optim - Solver · Orchestrates training and evaluation loops
engine/solver - Distributed utils · Multi-GPU coordination, logging, and profiling support
engine/misc/dist_utils.py
Deployment tools
Export, inference, benchmarking, and visualization
- Export tools · ONNX and export utilities for downstream runtimes
tools/deployment - Inference tools · PyTorch, ONNX Runtime, TensorRT, and OpenVINO inference
tools/inference - Benchmark tools · FLOPs, params, and latency measurement utilities
tools/benchmark - Visualization · Prediction visualization and FiftyOne-based inspection
tools/visualization - Dataset tools · Object365 remapping and resizing helpers
tools/dataset
Connections 24
- 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