# ifzhang/fairmot architecture

> Architecture diagram of the GitHub repository ifzhang/fairmot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ifzhang/fairmot
- Repository: https://github.com/ifzhang/fairmot

## Overview

##### Project Type and Purpose
- FairMOT is a research-grade, full-stack machine-learning pipeline for real-time multi-object tracking (MOT).
- It fuses object detection and person re-identification (“Re-ID”) in a single network backbone to achieve high tracking accuracy at 30+ FPS.

##### File Structure Analysis
- Top-level:
- build/Dockerfile – container definition with Python, PyTorch, FFmpeg, DCNv2 runtime.
- experiments/*.sh – shell scripts defining common training/evaluation workflows.
- requirements.txt – Python dependencies.
- assets/ – static images illustrating pipeline and demo GIFs.
- videos/ – sample input videos.
- src/ – core codebase split into:
- Entry scripts (train.py, track.py, track_half.py, demo.py, detect.py, detection_demo.py, test_det.py, test_emb.py)
- data/ – precomputed data splits and raw paths.
- lib/ – modular packages:
– cfg/ – dataset and model configuration JSONs
– datasets/ – PyTorch dataset wrappers and factories
– models/ – network definitions (common, backbones, heads, loss, decode, data_parallel)
– tracker/ – multi-object tracking logic (Hungarian matcher, Kalman filter, base track)
– tracking_utils/ – I/O, evaluation metrics, visualization, NMS, timing, logging
– trains/ – training loops and scheduler factories
– utils/ – image and post-processing helpers
– logger.py, opts.py – global logging and command-line option parsing

##### README Insights
- Dependencies: Python 3.8, PyTorch ≥1.7, DCNv2, FFmpeg
- Data preparation: CrowdHuman, MIX (Caltech, CityPersons, MOT16/17, etc.), MOT15, MOT20
- Pretrained weights & shell scripts automate common train/eval flows

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Data Storage"
        DS1["Raw Datasets (CrowdHuman, MOT)"]:::data
        DS2["Precomputed Paths (src/data/)"]:::data
    end
    click DS2 "https://github.com/ifzhang/fairmot/tree/master/src/data/"

    subgraph "Data Loader & Preprocessor"
        Cfg["Config JSONs"]:::data
        DF["dataset_factory.py"]:::data
        JDE["jde.py"]:::data
        JDEY["jde_yolov5.py"]:::data
        GDP["gen_data_path.py"]:::data
        GL15["gen_labels_15.py"]:::data
        GL16["gen_labels_16.py"]:::data
        GL20["gen_labels_20.py"]:::data
        GCD["gen_labels_crowd_det.py"]:::data
        GCI["gen_labels_crowd_id.py"]:::data
    end
    click Cfg "https://github.com/ifzhang/fairmot/tree/master/src/lib/cfg/"
    click DF "https://github.com/ifzhang/fairmot/blob/master/src/lib/datasets/dataset_factory.py"
    click JDE "https://github.com/ifzhang/fairmot/blob/master/src/lib/datasets/dataset/jde.py"
    click JDEY "https://github.com/ifzhang/fairmot/blob/master/src/lib/datasets/dataset/jde_yolov5.py"
    click GDP "https://github.com/ifzhang/fairmot/blob/master/src/gen_data_path.py"
    click GL15 "https://github.com/ifzhang/fairmot/blob/master/src/gen_labels_15.py"
    click GL16 "https://github.com/ifzhang/fairmot/blob/master/src/gen_labels_16.py"
    click GL20 "https://github.com/ifzhang/fairmot/blob/master/src/gen_labels_20.py"
    click GCD "https://github.com/ifzhang/fairmot/blob/master/src/gen_labels_crowd_det.py"
    click GCI "https://github.com/ifzhang/fairmot/blob/master/src/gen_labels_crowd_id.py"

    subgraph "Model Components"
        MC1["Networks Configs"]:::model
        MC2["dlav0.py"]:::model
        MC3["pose_dla_conv.py"]:::model
        MC4["pose_dla_dcn.py"]:::model
        MC5["pose_hrnet.py"]:::model
        MC6["resnet_dcn.py"]:::model
        MC7["resnet_fpn_dcn.py"]:::model
        MC8["common.py"]:::model
        MC9["model.py"]:::model
        MC10["decode.py"]:::model
        MC11["losses.py"]:::model
        MC12["yolo.py"]:::model
        MC13["data_parallel.py"]:::model
        MC14["utils.py"]:::model
        MC15["scatter_gather.py"]:::model
    end
    click MC1 "https://github.com/ifzhang/fairmot/tree/master/src/lib/models/networks/config/"
    click MC2 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/networks/dlav0.py"
    click MC3 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/networks/pose_dla_conv.py"
    click MC4 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/networks/pose_dla_dcn.py"
    click MC5 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/networks/pose_hrnet.py"
    click MC6 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/networks/resnet_dcn.py"
    click MC7 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/networks/resnet_fpn_dcn.py"
    click MC8 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/common.py"
    click MC9 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/model.py"
    click MC10 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/decode.py"
    click MC11 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/losses.py"
    click MC12 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/yolo.py"
    click MC13 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/data_parallel.py"
    click MC14 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/utils.py"
    click MC15 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/scatter_gather.py"

    subgraph "Training Engine"
        TE1["base_trainer.py"]:::model
        TE2["mot.py"]:::model
        TE3["train_factory.py"]:::model
        TE4["train.py"]:::script
    end
    click TE1 "https://github.com/ifzhang/fairmot/blob/master/src/lib/trains/base_trainer.py"
    click TE2 "https://github.com/ifzhang/fairmot/blob/master/src/lib/trains/mot.py"
    click TE3 "https://github.com/ifzhang/fairmot/blob/master/src/lib/trains/train_factory.py"
    click TE4 "https://github.com/ifzhang/fairmot/blob/master/src/train.py"

    subgraph "Inference & Tracking"
        IT1["detect.py"]:::script
        IT2["detection_demo.py"]:::script
        IT3["track.py"]:::script
        IT4["track_half.py"]:::script
        IT5["demo.py"]:::script
        IT6["basetrack.py"]:::algo
        IT7["matching.py"]:::algo
        IT8["multitracker.py"]:::algo
        IT9["decode.py"]:::algo
        IT10["kalman_filter.py"]:::algo
        IT11["nms.py"]:::algo
    end
    click IT1 "https://github.com/ifzhang/fairmot/blob/master/src/detect.py"
    click IT2 "https://github.com/ifzhang/fairmot/blob/master/src/detection_demo.py"
    click IT3 "https://github.com/ifzhang/fairmot/blob/master/src/track.py"
    click IT4 "https://github.com/ifzhang/fairmot/blob/master/src/track_half.py"
    click IT5 "https://github.com/ifzhang/fairmot/blob/master/src/demo.py"
    click IT6 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracker/basetrack.py"
    click IT7 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracker/matching.py"
    click IT8 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracker/multitracker.py"
    click IT9 "https://github.com/ifzhang/fairmot/blob/master/src/lib/models/decode.py"
    click IT10 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/kalman_filter.py"
    click IT11 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/nms.py"

    subgraph "Evaluation & Visualization"
        EV1["evaluation.py"]:::algo
        EV2["visualization.py"]:::algo
        EV3["io.py"]:::algo
        EV4["log.py"]:::algo
        EV5["timer.py"]:::algo
        EV6["utils.py"]:::algo
    end
    click EV1 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/evaluation.py"
    click EV2 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/visualization.py"
    click EV3 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/io.py"
    click EV4 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/log.py"
    click EV5 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/timer.py"
    click EV6 "https://github.com/ifzhang/fairmot/blob/master/src/lib/tracking_utils/utils.py"

    subgraph "Orchestration & Env"
        OE1["Dockerfile"]:::script
        OE2["experiments/*.sh"]:::script
    end
    click OE1 "https://github.com/ifzhang/fairmot/tree/master/build/Dockerfile"
    click OE2 "https://github.com/ifzhang/fairmot/tree/master/experiments/"

    subgraph "Global Logging & Options"
        GO1["logger.py"]:::script
        GO2["opts.py"]:::script
    end
    click GO1 "https://github.com/ifzhang/fairmot/blob/master/src/lib/logger.py"
    click GO2 "https://github.com/ifzhang/fairmot/blob/master/src/lib/opts.py"

    DS2 --> Cfg
    Cfg --> DF
    DF --> MC1
    DF --> MC9
    MC1 --> MC2
    MC9 --> TE1
    MC9 --> IT1
    TE4 --> TE1
    TE1 --> MC9
    DF --> IT3
    MC9 --> IT3
    IT3 --> EV1
    OE2 --> TE4
    OE2 --> IT3
    OE1 --> OE2
    GO1 --> TE1
    GO1 --> IT3

    classDef data fill:#BBDEFB,stroke:#2196F3,color:#0D47A1;
    classDef model fill:#C8E6C9,stroke:#388E3C,color:#1B5E20;
    classDef algo fill:#FFE0B2,stroke:#F57C00,color:#E65100;
    classDef script fill:#E0E0E0,stroke:#757575,color:#212121;
```
