CenterTrack

repository·master·Indexed 25 days ago

https://github.com/xingyizhou/centertrack

A simultaneous object detection and tracking algorithm that uses center points to associate objects across frames. It supports 2D tracking, 3D monocular tracking, and pose tracking, offering a faster and simpler alternative to traditional tracking-by-detection pipelines. The project includes support for datasets such as MOT 2017, KITTI Tracking, nuScenes, CrowdHuman, and COCO.

Tokens
8.3K
Snippets
14
Records
53
Agent score
79%

What's inside CenterTrack

  1. How CenterTrack works: Simultaneous Detection and Tracking

    master

    CenterTrack is a simultaneous detection and tracking algorithm. Unlike traditional tracking-by-detection pipelines that separate these steps, CenterTrack takes the current frame, the previous frame, and a heatmap rendered from previous tracking results as input.

    It predicts:

    1. The current detection heatmap.
    2. The offsets of detected objects to their centers in the previous frame.

    This allows the model to localize objects and predict their temporal associations in a single pass. It is designed to be online (no future information used) and real-time. The method can be extended to monocular 3D tracking by regressing additional 3D attributes.

  2. Evaluate CenterTrack on MOT17

    master

    To evaluate tracking performance on the MOT17 dataset using a pretrained model, run the test.py script with the appropriate flags.

    Key arguments:

    • --exp_id: Experiment identifier.
    • --dataset: Set to mot.
    • --dataset_version: e.g., 17halfval or 17test.
    • --pre_hm: Enables the input heatmap.
    • --ltrb_amodal: Uses left, top, right, bottom bounding box representation to detect out-of-image bounding boxes (recommended for MOT datasets).
    • --track_thresh: Score threshold for predicting a bounding box ($ heta$ in the paper).
    • --pre_thresh: Score threshold for feeding the heatmap to the next frame ($ au$ in the paper).
    • --load_model: Path to the pretrained .pth model.
    • --public_det: Use public detection results.
    • --load_results: Path to the public detection JSON file.
    • --debug 2: Append this flag to visualize predictions.

    Ensure models are placed in CenterTrack_ROOT/models/ before running.

  3. Download CenterTrack pre-trained models

    master

    Pre-trained models for various tasks (MOT17, KITTI, nuScenes, COCO) can be downloaded from the official Google Drive repository.

    Environment Requirements:

    • PyTorch 1.0
    • CUDA 10.0
    • CUDNN 7.5

    Model Categories:

    • 2D Bounding Box Tracking: Models for MOT17 and KITTI 2D datasets.
    • Monocular 3D Detection/Tracking: Models for the nuScenes dataset.
    • COCO Tracking: Models provided for demonstration purposes only.

    Google Drive Link

  4. Evaluate CenterTrack on nuScenes 3D Tracking

    master

    To evaluate 3D tracking performance on the nuScenes dataset, use the following command.

    Key arguments:

    • --exp_id: Experiment identifier.
    • --load_model: Path to the pretrained .pth model.
    • --dataset: Set to nuscenes.
    • --track_thresh: Score threshold for predicting a bounding box.
    • --pre_hm: Enables the input heatmap.
    python test.py tracking,ddd --exp_id nuScenes_3Dtracking --load_model ../models/nuScenes_3Dtracking.pth --dataset nuscenes --track_thresh 0.1 --pre_hm
  5. Prepare the COCO dataset

    master

    COCO is used for training demo systems for 80-category tracking or pose tracking.

    1. Download the 2017 Train, Val, and Test images from the COCO website.
    2. Download the 2017 train/val and test image info annotation files.
    3. Organize the data in ${CenterTrack_ROOT}/data/coco as follows:
    ${CenterTrack_ROOT}
    |-- data
    `-- |-- coco
        |-- annotations
        |   |-- instances_train2017.json
        |   |-- instances_val2017.json
        |   |-- person_keypoints_train2017.json
        |   |-- person_keypoints_val2017.json
        |   |-- image_info_test-dev2017.json
        |---|-- train2017
        |---|-- val2017
        `---|-- test2017
  6. Prepare the nuScenes dataset

    master

    nuScenes is used for 3D object tracking and pretraining KITTI models.

    1. Download the "Keyframe blobs" (images only) and the maps/metadata from the nuScenes website.
    2. Unzip, rename, and merge folders into ${CenterTrack_ROOT}/data/nuscenes/v1.0-trainval.
    3. Run the conversion script in the tools directory to create COCO annotations:
    python convert_kitti_to_coco.py

    This will generate train.json, val.json, and test.json under data/nuscenes/annotations. Note that the nuscenes API is required for this preprocessing step.

    python convert_kitti_to_coco.py
  7. Train CenterTrack on a custom dataset

    master

    To train on a custom dataset, use the --dataset custom flag. You must provide annotations in COCO format (refer to convert_X_to_coco.py in the tools directory for examples). You will also need to specify the annotation path, image path, input resolution, and number of classes.

    Example command for training on a custom dataset (modeled after the MOT17 experiment):

    python main.py tracking --exp_id mot17_half_sc --dataset custom --custom_dataset_ann_path ../data/mot17/annotations/train_half.json --custom_dataset_img_path ../data/mot17/train/ --input_h 544 --input_w 960 --num_classes 1 --pre_hm --ltrb_amodal --same_aug --hm_disturb 0.05 --lost_disturb 0.4 --fp_disturb 0.1 --gpus 0,1
    python main.py tracking --exp_id mot17_half_sc --dataset custom --custom_dataset_ann_path ../data/mot17/annotations/train_half.json --custom_dataset_img_path ../data/mot17/train/ --input_h 544 --input_w 960 --num_classes 1 --pre_hm --ltrb_amodal --same_aug --hm_disturb 0.05 --lost_disturb 0.4 --fp_disturb 0.1 --gpus 0,1
  8. Prepare the KITTI Tracking dataset

    master

    KITTI Tracking is used for 2D tracking training and evaluation.

    1. Download the images, annotations, and calibration information from the KITTI Tracking website and unzip them.
    2. Place or symlink the data into ${CenterTrack_ROOT}/data/kitti_tracking following the required structure.
    3. Run the conversion script in the tools directory to convert annotations to COCO format:
    python convert_kitti_to_coco.py

    The resulting structure should include a label_02_val_half and label_02_train_half directory, along with a annotations folder containing tracking_train.json, tracking_test.json, tracking_train_half.json, and tracking_val_half.json.

    python convert_kitti_to_coco.py
  9. Run CenterTrack Demos (Video, Webcam, Images)

    master

    CenterTrack supports several demo modes including video files, image folders, and live webcam feeds. You must first download the appropriate models from the Model zoo and place them in CenterNet_ROOT/models/.

    Monocular 3D Tracking

    To test monocular 3D tracking, use the tracking,ddd task. You must specify --test_focal_length to convert image coordinates to 3D. For the provided nuscenes_mini.mp4 (resolution 800x448), use 633 (half of the typical nuScenes focal length).

    python demo.py tracking,ddd --load_model ../models/nuScenes_3Dtracking.pth --dataset nuscenes --pre_hm --track_thresh 0.1 --demo ../videos/nuscenes_mini.mp4 --test_focal_length 633

    80-Category Tracking

    For standard object detection and tracking:

    python demo.py tracking --load_model ../models/coco_tracking.pth --demo /path/to/image/or/folder/or/video

    Person/Pose Tracking

    To track specifically persons (using a model like mot17_half.pth), add --num_class 1. For pose tracking, use the tracking,multi_pose task:

    # Person tracking
    python demo.py tracking --load_model ../models/mot17_half.pth --num_class 1 --demo /path/to/image/or/folder/or/video
    
    # Pose tracking
    python demo.py tracking,multi_pose --load_model ../models/coco_pose.pth --demo /path/to/image/or/folder/or/video/or/webcam

    Webcam Demo

    python demo.py tracking --load_model ../models/coco_tracking.pth --demo webcam

    Tip: Add --debug 2 to visualize heatmap and offset predictions.

    python demo.py tracking,ddd --load_model ../models/nuScenes_3Dtracking.pth --dataset nuscenes --pre_hm --track_thresh 0.1 --demo ../videos/nuscenes_mini.mp4 --test_focal_length 633
  10. Train CenterTrack on custom datasets

    master

    Training scripts are located in the experiments/ directory.

    Guidelines for training:

    • Experiment Names: The experiment names in the scripts correspond to the model names available in the model zoo.
    • Resuming Training: If training is interrupted, append the --resume flag to your command. The system will automatically find the latest model associated with the same --exp_id.
    • Pretraining: Some experiments require a model pretrained on a different dataset. You must either download the required pretrained model from the model zoo or train that model first before starting the current experiment.
  11. Install CenterTrack

    master

    Follow these steps to set up the CenterTrack environment. The project was tested on Ubuntu 16.04, Anaconda Python 3.6, CUDA 10.0, and PyTorch v1.0. It is compatible with PyTorch <=1.4 and Python >=0.4 (note: for PyTorch <1.0, you must switch the DCNv2 version).

    1. Create a Conda Environment

    It is highly recommended to use a dedicated environment:

    conda create --name CenterTrack python=3.6
    conda activate CenterTrack

    2. Install PyTorch

    conda install pytorch torchvision -c pytorch

    3. Install COCOAPI

    pip install cython; pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'

    4. Clone the Repository

    Use the --recursive flag to ensure submodules are included:

    CenterTrack_ROOT=/path/to/clone/CenterTrack
    git clone --recursive https://github.com/xingyizhou/CenterTrack $CenterTrack_ROOT

    5. Install Requirements

    pip install -r requirements.txt

    6. Compile DCNv2

    Navigate to the DCNv2 directory within the source tree and run the make script:

    cd $CenterTrack_ROOT/src/lib/model/networks/DCNv2
    ./make.sh

    7. Download Models

    Download the required pre-trained models and place them in the $CenterTrack_ROOT/models/ directory. Available models include:

    • Monocular 3D tracking
    • 80-category tracking
    • Pose tracking
    conda create --name CenterTrack python=3.6
    conda activate CenterTrack
    conda install pytorch torchvision -c pytorch
    pip install cython; pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
    git clone --recursive https://github.com/xingyizhou/CenterTrack $CenterTrack_ROOT
    pip install -r requirements.txt
    cd $CenterTrack_ROOT/src/lib/model/networks/DCNv2
    ./make.sh
  12. Evaluate CenterTrack on KITTI Tracking

    master

    To evaluate 2D vehicle tracking performance on the KITTI dataset, use the following command structure. Ensure the model is located in the models/ directory.

    Key arguments:

    • --exp_id: Experiment identifier.
    • --dataset: Set to kitti_tracking.
    • --dataset_version: e.g., val_half.
    • --pre_hm: Enables the input heatmap.
    • --track_thresh: Score threshold for predicting a bounding box.
    • --load_model: Path to the pretrained .pth model.
    python test.py tracking --exp_id kitti_half --dataset kitti_tracking --dataset_version val_half --pre_hm --track_thresh 0.4 --load_model ../models/kitti_half.pth