How fundamentalvision/deformable-detr works
Project type and purpose
• This is a research codebase for “Deformable DETR,” an end‑to‑end object detection system built on PyTorch. It provides training, evaluation, custom CUDA operators, and tools for distributed and slurm‐based launches.
File structure
• Top‐level scripts:
• main.py / benchmark.py – entry points for training/evaluation/benchmarking
• engine.py – orchestrates the training/evaluation loop
• configs/ – bash scripts encoding hyperparameters and model variants
• datasets/ – data loading, transforms, samplers, COCO‐specific IO and evaluation
• models/ – network definitions (ResNet backbone, Deformable Transformer, heads)
• models/ops/ – custom CUDA/C++ kernels for deformable attention
• tools/ – scripts to launch distributed jobs (single‑node, multi‑node, slurm)
• figs/ and docs/ – illustrations and changelog for reference
• requirements.txt – Python dependencies
README for additional insights
• It describes the high‑level architecture (backbone + deformable transformer encoder/decoder + detection head), usage patterns (single vs. multi‑node training, evaluation), and custom operator compilation.
Components
a. Main components:
1. Configuration & CLI layer (configs/ + tools/launch scripts)
2. Data layer (datasets/ + transforms + data prefetcher)
3. Model layer (models/):
– Backbone (ResNet)
– Deformable Transformer (encoder + decoder)
– Position encoding
– Matcher (Hungarian matching)
4. Custom ops module (models/ops/): CPU/CUDA kernels for deformable attention
5. Training & evaluation engine (engine.py + main.py)
6. Utilities (logging, checkpointing, plotting)
7. External dependencies: COCO dataset storage, PyTorch, CUDA toolkits
b. Relationships & interactions:
• Config/CLI → invokes main.py → parses config → calls engine
• Engine:
• pulls batches from Data layer → applies transforms → feeds to Model
• Model → uses custom ops for efficient attention → produces predictions
• Engine computes loss (with matcher), backprop via PyTorch → optimizer update
• Checkpointing & logging utilities record metrics
• During inference: same flow minus backward pass; evaluation uses datasets/coco_eval
• Custom ops: compiled at start, loaded by Model layer for forward/backward
c. Architectural patterns & principles:
• Modular separation: data / model / training engine / tools
• Extensibility: config scripts allow many model variants
• Performance optimization: custom low‑level operators; data prefetcher
• Distributed training support via launch scripts
d. Key technologies & libraries:
• PyTorch & torchvision
• CUDA/C++ for custom kernels
• Shell scripts for orchestration
• COCO dataset format
Detailed breakdown
• Config & Launch layer: run_dist_launch.sh, run_dist_slurm.sh → feeds to main.py
• Data layer:
• datasets/coco.py, transforms.py, data_prefetcher.py → PyTorch DataLoader
• Model layer:
• models/backbone.py → features → models/deformable_transformer.py → queries → models/deformable_detr.py heads
• models/position_encoding.py, matcher.py, segmentation.py
• Custom ops block:
• models/ops/modules/ms_deform_attn.py (Python binding)
• C++/CUDA src under models/ops/src → compiled via make.sh
• Engine & main:
• engine.py loops epochs, step, validation (calls coco_eval)
• benchmark.py for speed tests
• Utilities:
• util/box_ops.py, misc.py, plot_utils.py
• External:
• COCO dataset directory → annotations + images
• PyTorch & CUDA runtime