How zhizhongchai/orf-net works
Project Type and Purpose
• ORF-Net is a research-oriented deep learning framework built on top of Detectron2/AdelaiDet for omni-supervised rib fracture detection in chest radiology images.
• It provides data loading and augmentation, configurable model architectures (backbones, FPNs, heads), custom CUDA/C++ layers, training/evaluation pipelines, demo/inference scripts, and ONNX export utilities.
File Structure Analysis
• Top-level package “adet/” holds core code:
• adet/config: YAML config loader, default settings
• adet/data: dataset builders, mappers, augmentations, common utilities
• adet/checkpoint: checkpoint saving/loading abstractions
• adet/modeling: modular detection/segmentation architectures (ATSS, FCOS, BlendMask, MEInst, SOLOv2, etc.)
• adet/layers: Python wrappers and C++/CUDA implementations of custom ops (BezierAlign, DefROIAlign, ml_nms, deform_conv, GCN, IoU loss)
• adet/evaluation: evaluation scripts for object and text detection
• adet/utils and structures: inter-module utilities, visualization, communication
• configs/: directory of pre-written YAMLs for dozens of model configurations and dataset setups
• tools/train_net.py: entry point for training with config-file parameter
• demo/: inference utilities (demo.py, predictor.py)
• onnx/: scripts to export a trained PyTorch model to ONNX, then to Caffe/NCNN runtimes
• datasets/: dataset preparation scripts
• docs/: Sphinx documentation
• setup.py: installation and build of the package
Key Insights from README
• Emphasizes dependency on Detectron2 (specific commit) and installation via python setup.py build develop
• Training is driven by tools/train_net.py with a config file and GPU settings
• Demo and ONNX export are provided as standalone scripts
Diagramming the Architecture
a. Main Components to Represent
• Data Ingestion & Augmentation
• Config Management & Registry
• Model Component Library
• Custom Layer Extensions (C++/CUDA)
• Training & Evaluation Pipeline
• Inference & Demo Scripts
• ONNX Export Flow
• External Dependencies (Detectron2, PyTorch, CUDA)
b. Relationships and Interactions
• Data flows from raw images → datasets/prepare scripts → adet/data → DataLoader
• DataLoader outputs batched tensors → Model (backbone → neck → head)
• Model uses custom ops from adet/layers (via Python wrappers and C++/CUDA kernels)
• Checkpoint manager writes/loads model weights to disk (adet/checkpoint)
• Training script orchestrates data, model, and loss → optimizer → checkpoint → evaluation
• Evaluation module reads predictions and ground truth to compute metrics
• Demo/predictor loads checkpoint, runs inference, and visualizes results
• ONNX exporter loads the PyTorch model, traces graph, outputs ONNX file, and invokes conversion scripts
c. Architectural Patterns & Principles
• Modular design: each concern (data, model, layers, config, checkpoint) in its own package
• Plugin architecture: new model definitions and layers are discovered via registry
• Separation of concerns: configs separate from code, core logic independent of CLI scripts
• Extension through custom CUDA/C++ for performance-critical ops
d. Key Technologies and Frameworks
• Detectron2 for base object detection
• PyTorch as the deep learning engine
• Custom C++/CUDA kernels for specialized layers
• ONNX for cross-framework export
• YAML for configuration management