### MMTracking Example Data Pipeline Configuration Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_data_pipeline.md Provides an example configuration for a training data pipeline in MMTracking, demonstrating the use of custom pipelines like `LoadMultiImagesFromFile`, `SeqResize`, `VideoCollect`, and `ConcatVideoReferences` for video object detection tasks. ```APIDOC ## MMTracking Example Data Pipeline Configuration ### Description This is an example configuration for a training data pipeline in MMTracking. It showcases a sequence of transformations tailored for video object detection, including loading multiple images, sampling annotations, resizing, flipping, normalization, padding, collecting video-specific data, concatenating references, and formatting the output for model input. ### Method This configuration is used within the dataset definition to specify the data preprocessing steps. ### Endpoint N/A (This is a configuration example, not an API endpoint) ### Parameters This is a configuration snippet and does not have direct parameters. The parameters are defined within each pipeline dictionary. ### Request Example N/A ### Response N/A ### Configuration Example ```python train_pipeline = [ dict(type='LoadMultiImagesFromFile'), dict(type='SeqLoadAnnotations', with_bbox=True, with_track=True), dict(type='SeqResize', img_scale=(1000, 600), keep_ratio=True), dict(type='SeqRandomFlip', share_params=True, flip_ratio=0.5), dict(type='SeqNormalize', **img_norm_cfg), dict(type='SeqPad', size_divisor=16), dict( type='VideoCollect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_instance_ids']), dict(type='ConcatVideoReferences'), dict(type='SeqDefaultFormatBundle', ref_prefix='ref') ] ``` ``` -------------------------------- ### Install MMTracking and Dependencies Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Installs the required libraries including MMCV and MMDetection, clones the MMTracking repository, and performs an editable installation of the package. ```python # install MMCV !pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/index.html # install MMDetection !pip install mmdet # clone the MMTracking repository !git clone https://github.com/open-mmlab/mmtracking.git %cd mmtracking # install MMTracking and its dependencies !pip install -r requirements/build.txt !pip install -e . ``` -------------------------------- ### Example MMTracking Training Data Pipeline Configuration Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_data_pipeline.md This is an example configuration for a training data pipeline in MMTracking. It demonstrates a sequence of transformations including loading multiple images, sampling annotations, resizing, flipping, normalization, padding, collecting video-specific keys, concatenating references, and formatting the output for the model. ```python train_pipeline = [ dict(type='LoadMultiImagesFromFile'), dict(type='SeqLoadAnnotations', with_bbox=True, with_track=True), dict(type='SeqResize', img_scale=(1000, 600), keep_ratio=True), dict(type='SeqRandomFlip', share_params=True, flip_ratio=0.5), dict(type='SeqNormalize', **img_norm_cfg), dict(type='SeqPad', size_divisor=16), dict( type='VideoCollect', keys=['img', 'gt_bboxes', 'gt_labels', 'gt_instance_ids']), dict(type='ConcatVideoReferences'), dict(type='SeqDefaultFormatBundle', ref_prefix='ref') ] ``` -------------------------------- ### Install MMTracking and its Dependencies Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Installs the MMTracking library and its core dependencies, including mmcv-full and mmdet. This process involves cloning the repository and then installing the project locally, ensuring all necessary components for tracking are available. ```bash Cloning into 'mmtracking'... remote: Enumerating objects: 4189, done. remote: Counting objects: 100% (4189/4189), done. remote: Compressing objects: 100% (1638/1638), done. remote: Total 4189 (delta 2502), reused 3981 (delta 2433), pack-reused 0 Receiving objects: 100% (4189/4189), 1.67 MiB | 17.14 MiB/s, done. Resolving deltas: 100% (2502/2502), done. /content/mmtracking Requirement already satisfied: cython in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 1)) Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from -r requirements/build.txt (line 2)) Obtaining file:///content/mmtracking Collecting attributee==0.1.5 Downloading attributee-0.1.5.tar.gz (11 kB) Collecting dotty_dict Downloading dotty_dict-1.3.0.tar.gz (32 kB) Collecting lap Downloading lap-0.4.0.tar.gz (1.5 MB) Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) Collecting mmcls>=0.16.0 Downloading mmcls-0.22.1-py2.py3-none-any.whl (548 kB) Collecting motmetrics Downloading motmetrics-1.2.5-py3-none-any.whl (161 kB) Requirement already satisfied: opencv-python in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) Requirement already satisfied: pandas<=1.3.5 in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) Collecting pycocotools<=2.0.2 Downloading pycocotools-2.0.2.tar.gz (23 kB) Requirement already satisfied: scipy<=1.7.3 in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) Requirement already satisfied: seaborn in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) Requirement already satisfied: terminaltables in /usr/local/lib/python3.7/dist-packages (from mmtrack==0.12.0) ``` -------------------------------- ### Configure Learning Rate Schedules Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_runtime.md Examples of configuring different learning rate policies such as 'poly' and 'CosineAnnealing' to control training progression. ```python lr_config = dict(policy='poly', power=0.9, min_lr=1e-4, by_epoch=False) lr_config = dict( policy='CosineAnnealing', warmup='linear', warmup_iters=1000, warmup_ratio=1.0 / 10, min_lr_ratio=1e-5) ``` -------------------------------- ### Training Models Source: https://context7.com/open-mmlab/mmtracking/llms.txt Provides examples for training models using MMTracking, supporting single-GPU, multi-GPU, and distributed training modes. It also shows how to override configurations and resume training from checkpoints. ```APIDOC ## Training Models Training in MMTracking supports single-GPU, multi-GPU, and distributed training modes. The `train_model` function handles data loading, model optimization, and checkpoint saving. ### Single GPU Training ```bash python tools/train.py configs/mot/bytetrack/bytetrack_yolox_x_crowdhuman_mot17-private-half.py --work-dir ./work_dirs/bytetrack ``` ### Multi-GPU Training (8 GPUs) ```bash bash ./tools/dist_train.sh configs/mot/bytetrack/bytetrack_yolox_x_crowdhuman_mot17-private-half.py 8 --work-dir ./work_dirs/bytetrack ``` ### Training with Config Overrides ```bash python tools/train.py configs/vid/dff/dff_faster_rcnn_r101_dc5_1x_imagenetvid.py --cfg-options optimizer.lr=0.01 total_epochs=12 ``` ### Resume Training from Checkpoint ```bash python tools/train.py configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py --resume-from work_dirs/siamese_rpn/latest.pth ``` ### Train Detector for MOT ```bash python tools/train.py configs/det/faster-rcnn_r50_fpn_4e_mot17-half.py --work-dir ./work_dirs/det_mot17 ``` ### Train ReID Model for MOT ```bash python tools/train.py configs/reid/resnet50_b32x8_MOT17.py --work-dir ./work_dirs/reid_mot17 ``` ``` -------------------------------- ### Install TrackEval for MOT Evaluation Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Installs the TrackEval library from its GitHub repository, which is used for evaluating multiple object tracking (MOT) performance. This is a crucial step for benchmarking tracking algorithms. ```bash # used to MOT evaluation !pip install git+https://github.com/JonathonLuiten/TrackEval.git ``` -------------------------------- ### Initialize and Train ReID Model Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb This script initializes a ReID model with pre-trained weights, builds the dataset from configuration, and starts the training process using the MMTracking and MMDetection APIs. ```python from mmtrack.datasets import build_dataset from mmdet.apis import train_detector as train_model from mmtrack.models import build_reid as build_model model = build_model(cfg.model.reid) model.init_weights() datasets = [build_dataset(cfg.data.train)] model.CLASSES = datasets[0].CLASSES train_model(model, datasets, cfg) ``` -------------------------------- ### Python: Model Initialization Logs Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb This snippet shows example log outputs during the initialization of FasterRCNN and BaseReID models in MMTracking. It details the loading of pre-trained checkpoints. ```python 2022-04-20 05:29:38,354 - mmtrack - INFO - initialize FasterRCNN with init_cfg {'type': 'Pretrained', 'checkpoint': './tutorial_exps/detector/epoch_4.pth'} 2022-04-20 05:29:38,356 - mmcv - INFO - load model from: ./tutorial_exps/detector/epoch_4.pth 2022-04-20 05:29:38,359 - mmcv - INFO - load checkpoint from local path: ./tutorial_exps/detector/epoch_4.pth 2022-04-20 05:29:38,667 - mmtrack - INFO - initialize BaseReID with init_cfg {'type': 'Pretrained', 'checkpoint': './tutorial_exps/reid/epoch_2.pth'} 2022-04-20 05:29:38,669 - mmcv - INFO - load model from: ./tutorial_exps/reid/epoch_2.pth 2022-04-20 05:29:38,672 - mmcv - INFO - load checkpoint from local path: ./tutorial_exps/reid/epoch_2.pth ``` -------------------------------- ### Example: Testing SiameseRPN++ on LaSOT (Single GPU) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the SiameseRPN++ model on the LaSOT dataset using a single GPU. It specifies the configuration file, checkpoint path, output file, and evaluates success, precision, and normed precision metrics. ```shell python tools/test.py configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py \ --checkpoint checkpoints/siamese_rpn_r50_1x_lasot_20211203_151612-da4b3c66.pth \ --out results.pkl \ --eval track ``` -------------------------------- ### Python Configuration for Detector and ReID Model Initialization Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Demonstrates how to configure detector and re-identification models within a Python script, specifying pre-trained checkpoints for initialization. This is typically used for custom model setups. ```python model = dict( detector=dict( init_cfg=dict( type='Pretrained', checkpoint='/path/to/detector_model')), reid=dict( init_cfg=dict( type='Pretrained', checkpoint='/path/to/reid_model')) ) ``` -------------------------------- ### Example: Train DFF Model on ImageNet VID Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md This shell command provides a practical example of training a DFF model for Video Instance Detection (VID) on the ImageNet VID and DET datasets. It utilizes the `dist_train.sh` script for distributed training across 8 GPUs and specifies the output directory for logs and checkpoints. ```shell bash ./tools/dist_train.sh ./configs/vid/dff/dff_faster_rcnn_r101_dc5_1x_imagenetvid.py 8 \ --work-dir ./work_dirs/ ``` -------------------------------- ### Example: Testing Tracktor on MOT17 (Single GPU) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the Tracktor model on the MOT17 dataset using a single GPU. It specifies the configuration file and evaluates CLEAR MOT metrics. ```shell python tools/test.py configs/mot/tracktor/tracktor_faster-rcnn_r50_fpn_4e_mot17-public-half.py \ --eval track ``` -------------------------------- ### Configure a Custom Motion Model Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_vid_model.md Example of how to configure a custom motion model in a configuration file. It specifies the type of the motion model and its arguments. ```python motion=dict( type='MyFlowNet', arg1=xxx, arg2=xxx) ``` -------------------------------- ### Configure a Custom Aggregator Model Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_vid_model.md An example configuration for a custom aggregator model, specifying its type and necessary arguments. ```python aggregator=dict( type='MyAggregator', arg1=xxx, arg2=xxx) ``` -------------------------------- ### Example: Testing SiameseRPN++ on LaSOT (8 GPUs) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the SiameseRPN++ model on the LaSOT dataset using 8 GPUs. It utilizes the distributed testing script and specifies the configuration file, checkpoint path, output file, and evaluates success, precision, and normed precision metrics. ```shell ./dist_test.sh configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py 8 \ --checkpoint checkpoints/siamese_rpn_r50_1x_lasot_20211203_151612-da4b3c66.pth \ --out results.pkl \ --eval track ``` -------------------------------- ### Example: Testing MaskTrack R-CNN on YouTube-VIS (Single GPU, Format Only) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the MaskTrack R-CNN model on YouTube-VIS 2019 using a single GPU, formatting results for submission. It specifies the configuration file, checkpoint, output path, and uses `--format-only` with evaluation options. ```shell python tools/test.py \ configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py \ --checkpoint checkpoints/masktrack_rcnn_r50_fpn_12e_youtubevis2019_20211022_194830-6ca6b91e.pth \ --out ${RESULTS_PATH}/results.pkl \ --format-only \ --eval-options resfile_path=${RESULTS_PATH} ``` -------------------------------- ### Example: Testing Tracktor on MOT17 (8 GPUs) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the Tracktor model on the MOT17 dataset using 8 GPUs. It utilizes the distributed testing script and specifies the configuration file, evaluating CLEAR MOT metrics. ```shell ./dist_test.sh configs/mot/tracktor/tracktor_faster-rcnn_r50_fpn_4e_mot17-public-half.py 8 \ --eval track ``` -------------------------------- ### Example: Testing DFF on ImageNet VID (Single GPU) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the DFF model on the ImageNet VID dataset using a single GPU. It specifies the configuration file, checkpoint path, output file, and evaluates bounding box mAP. ```shell python tools/test.py configs/vid/dff/dff_faster_rcnn_r101_dc5_1x_imagenetvid.py \ --checkpoint checkpoints/dff_faster_rcnn_r101_dc5_1x_imagenetvid_20201218_172720-ad732e17.pth \ --out results.pkl \ --eval bbox ``` -------------------------------- ### Example: Testing DFF on ImageNet VID (8 GPUs) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the DFF model on the ImageNet VID dataset using 8 GPUs. It utilizes the distributed testing script and specifies the configuration file, checkpoint path, output file, and evaluates bounding box mAP. ```shell ./dist_test.sh configs/vid/dff/dff_faster_rcnn_r101_dc5_1x_imagenetvid.py 8 \ --checkpoint checkpoints/dff_faster_rcnn_r101_dc5_1x_imagenetvid_20201218_172720-ad732e17.pth \ --out results.pkl \ --eval bbox ``` -------------------------------- ### Evaluation Configuration Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/config_sot.md Sets up the evaluation hook, specifying metrics (e.g., 'track'), interval, start epoch, and the rule for saving the best model based on a metric like 'success'. ```python evaluation = dict( metric=['track'], interval=1, start=10, rule='greater', save_best='success') ``` -------------------------------- ### Example: Testing MaskTrack R-CNN on YouTube-VIS (8 GPUs, Format Only) Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Tests the MaskTrack R-CNN model on YouTube-VIS 2019 using 8 GPUs, formatting results for submission. It utilizes the distributed testing script and specifies the configuration file, checkpoint, output path, and uses `--format-only` with evaluation options. ```shell ./dist_test.sh \ configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py \ --checkpoint checkpoints/masktrack_rcnn_r50_fpn_12e_youtubevis2019_20211022_194830-6ca6b91e.pth \ --out ${RESULTS_PATH}/results.pkl \ --format-only \ --eval-options resfile_path=${RESULTS_PATH} ``` -------------------------------- ### Manage Hierarchical Configs Source: https://context7.com/open-mmlab/mmtracking/llms.txt Shows how to inherit from base configuration files and override specific parameters using dictionary updates or the _delete_ flag. This system allows for modular model and training setup. ```python _base_ = [ '../_base_/models/faster_rcnn_r50_fpn.py', '../_base_/datasets/mot_challenge.py', '../_base_/default_runtime.py' ] model = dict( detector=dict( backbone=dict( depth=101, init_cfg=dict( type='Pretrained', checkpoint='torchvision://resnet101' ) ), roi_head=dict( bbox_head=dict(num_classes=1) ) ) ) data = dict( samples_per_gpu=4, train=dict( _delete_=True, type='CocoVideoDataset', ann_file='data/my_dataset/train.json', img_prefix='data/my_dataset/train/' ) ) optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) lr_config = dict(policy='step', step=[8, 11]) total_epochs = 12 evaluation = dict(interval=1, metric=['bbox', 'track']) ``` -------------------------------- ### Configure Logging Hooks in Python Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/config_sot.md Sets up various logging hooks for tracking training progress. Supports TextLoggerHook, TensorboardLoggerHook, and WandbLoggerHook. Requires 'wandb' to be installed for WandbLoggerHook. Other hooks like ClearMLLoggerHook are also supported via MMCV. ```python log_config = dict( interval=50, hooks=[ dict(type='TextLoggerHook', by_epoch=False), dict(type='TensorboardLoggerHook', by_epoch=False), dict(type='WandbLoggerHook', by_epoch=False, init_kwargs={'entity': "OpenMMLab", 'project': "MMTracking", 'config': cfg_dict}) ]) ``` -------------------------------- ### Initialize Visualization Demo Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb This Python snippet demonstrates how to set up variables for running a visualization demo using MMTracking. It specifies the configuration file and the checkpoint file paths required for initializing the visualization model. ```python # run vis demo from mmtrack.apis import inference_mot vis_config = './configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py' vis_checkpoint = './checkpoints/masktrack_rcnn_r50_fpn_12e_youtubevis2019_20211022_194830-6ca6b91e.pth' ``` -------------------------------- ### Run MMTracking Inference Demos Source: https://context7.com/open-mmlab/mmtracking/llms.txt Demonstrates how to execute various tracking and detection scripts for MOT, SOT, VID, and VIS tasks. These scripts require a config file, input video, and a model checkpoint. ```bash # Multi-Object Tracking demo python demo/demo_mot_vis.py \ configs/mot/deepsort/sort_faster-rcnn_fpn_4e_mot17-private.py \ --input demo/demo.mp4 \ --output mot_result.mp4 \ --checkpoint checkpoints/faster_rcnn_mot17.pth \ --score-thr 0.5 \ --device cuda:0 \ --show # Single Object Tracking demo python demo/demo_sot.py \ configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py \ --input demo/target_video.mp4 \ --output sot_result.mp4 \ --checkpoint checkpoints/siamese_rpn_r50.pth \ --gt_bbox_file demo/gt_bbox.txt \ --device cuda:0 # Video Object Detection demo python demo/demo_vid.py \ configs/vid/selsa/selsa_faster_rcnn_r101_dc5_1x_imagenetvid.py \ --input demo/video.mp4 \ --output vid_result.mp4 \ --checkpoint checkpoints/selsa_faster_rcnn_r101.pth \ --score-thr 0.5 \ --device cuda:0 # Video Instance Segmentation demo python demo/demo_mot_vis.py \ configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py \ --input demo/video.mp4 \ --output vis_result.mp4 \ --checkpoint checkpoints/masktrack_rcnn_r50.pth \ --show ``` -------------------------------- ### Verify PyTorch, MMCV, MMDetection, and MMTracking Installations Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb This Python code verifies the installations of PyTorch, torchvision, MMCV, MMDetection, and MMTracking by printing their versions and checking CUDA availability. It also retrieves MMCV's compiling CUDA and compiler versions. ```python # Check Pytorch installation import torch, torchvision print(torch.__version__, torch.cuda.is_available()) # Check mmcv installation from mmcv.ops import get_compiling_cuda_version, get_compiler_version print(get_compiling_cuda_version()) print(get_compiler_version()) # Check MMDetection installation import mmdet print(mmdet.__version__) # Check MMTracking installation import mmtrack print(mmtrack.__version__) ``` -------------------------------- ### Training Models in MMTracking Source: https://context7.com/open-mmlab/mmtracking/llms.txt Demonstrates how to train models using MMTracking's command-line tools. Supports single-GPU, multi-GPU, and distributed training. Allows configuration overrides and resuming training from checkpoints. ```python python tools/train.py configs/mot/bytetrack/bytetrack_yolox_x_crowdhuman_mot17-private-half.py \ --work-dir ./work_dirs/bytetrack ``` ```bash bash ./tools/dist_train.sh \ configs/mot/bytetrack/bytetrack_yolox_x_crowdhuman_mot17-private-half.py 8 \ --work-dir ./work_dirs/bytetrack ``` ```python python tools/train.py configs/vid/dff/dff_faster_rcnn_r101_dc5_1x_imagenetvid.py \ --cfg-options optimizer.lr=0.01 total_epochs=12 ``` ```python python tools/train.py configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py \ --resume-from work_dirs/siamese_rpn/latest.pth ``` ```python python tools/train.py configs/det/faster-rcnn_r50_fpn_4e_mot17-half.py \ --work-dir ./work_dirs/det_mot17 ``` ```python python tools/train.py configs/reid/resnet50_b32x8_MOT17.py \ --work-dir ./work_dirs/reid_mot17 ``` -------------------------------- ### Initialize Model and Run Inference Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Initializes a tracking model from a configuration and checkpoint, then processes frames from a video file for inference. It visualizes results frame by frame and saves them temporarily. ```python from mmtrack.apis import init_model, inference_mot import mmcv import tempfile vis_config = './configs/mot/fairmot/fairmot_faster-rcnn_r50_fpn_1x_mot17-public.py' vis_checkpoint = './checkpoints/fairmot_faster-rcnn_r50_fpn_1x_mot17-public_20210611_110019.pt' vis_model = init_model(vis_config, vis_checkpoint, device='cuda:0') imgs = mmcv.VideoReader(input_video) prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name for i, img in enumerate(imgs): result = inference_mot(vis_model, img, frame_id=i) vis_model.show_result( img, result, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/vis.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup() ``` -------------------------------- ### Model Publishing Preparation Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/useful_tools_scripts.md Prepares a model for distribution by converting weights to CPU tensors, removing optimizer states, and appending a hash ID to the filename. ```bash python tools/analysis/publish_model.py work_dirs/model.pth output_model.pth ``` -------------------------------- ### Execute Model Testing with MMTracking API Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Demonstrates how to build a dataset, initialize a model from a configuration, and run single-GPU inference. This workflow is essential for evaluating tracking performance on test datasets. ```python from mmtrack.datasets import build_dataloader from mmtrack.apis import init_model from mmcv.parallel import MMDataParallel from mmtrack.apis import single_gpu_test from mmtrack.datasets import build_dataset dataset = build_dataset(cfg.data.test) data_loader = build_dataloader( dataset, samples_per_gpu=1, workers_per_gpu=cfg.data.workers_per_gpu, dist=False, shuffle=False) # build the model and load checkpoint model = init_model(cfg) model = MMDataParallel(model, device_ids=cfg.gpu_ids) outputs = single_gpu_test(model, data_loader) ``` -------------------------------- ### Download and Extract MOT17 Toy Dataset Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Downloads the MOT17_tiny dataset from OpenMMLab servers and extracts it into the local data directory. This is a prerequisite for running training examples. ```bash !mkdir data !wget https://download.openmmlab.com/mmtracking/data/MOT17_tiny.zip -P ./data !unzip -q ./data/MOT17_tiny.zip -d ./data ``` -------------------------------- ### Configure Custom CocoVID Dataset Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_dataset.md Example of how to define a custom dataset in an MMTracking configuration file using the CocoVideoDataset type and specifying class names and data paths. ```python dataset_type = 'CocoVideoDataset' classes = ('a', 'b', 'c', 'd', 'e') data = dict( samples_per_gpu=2, workers_per_gpu=2, train=dict( type=dataset_type, classes=classes, ann_file='path/to/your/train/data'), val=dict( type=dataset_type, classes=classes, ann_file='path/to/your/val/data'), test=dict( type=dataset_type, classes=classes, ann_file='path/to/your/test/data')) ``` -------------------------------- ### Run Video Inference Demo Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Sets up the configuration and checkpoint paths for running a video inference demo using the `inference_vid` API from MMTracking. ```python # run vid demo from mmtrack.apis import inference_vid vid_config = './configs/vid/selsa/selsa_faster_rcnn_r50_dc5_1x_imagenetvid.py' vid_checkpoint = './checkpoints/selsa_faster_rcnn_r50_dc5_1x_imagenetvid_20201227_204835-2f5a4952.pth' ``` -------------------------------- ### Configuring Log Hook Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_runtime.md This configuration sets up the `log_config`, which manages multiple logger hooks. It defines the logging interval and includes examples of integrating `TextLoggerHook` and `TensorboardLoggerHook` for different logging outputs. ```python log_config = dict( interval=50, hooks=[ dict(type='TextLoggerHook'), dict(type='TensorboardLoggerHook') ]) ``` -------------------------------- ### Initialize and Run Video Object Detection Model Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Initializes a video object detection model from a configuration file and checkpoint. It then processes frames from an input video, performs inference, saves intermediate results as images, and finally compiles these images into an output video. Dependencies include mmcv and tempfile. ```python vid_model = init_model(vid_config, vid_checkpoint, device='cuda:0') imgs = mmcv.VideoReader(input_video) prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name for i, img in enumerate(imgs): result = inference_vid(vid_model, img, frame_id=i) vid_model.show_result( img, result, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/vid.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup() ``` -------------------------------- ### Training Workflow Configuration in MMTracking Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/config_vid.md Defines the workflow for the training runner. It specifies the phases of training and how many times each phase should be executed. For example, [('train', 1)] indicates a single training phase executed once. ```python workflow = [('train', 1)] ``` -------------------------------- ### Using Custom Hooks in Configuration Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_runtime.md This configuration snippet shows how to instantiate and use a custom hook named `MyHook` within the `custom_hooks` list in a configuration file. It includes parameters `a` and `b` for hook initialization and demonstrates how to set the hook's priority. ```python custom_hooks = [ dict(type='MyHook', a=a_value, b=b_value) ] ``` ```python custom_hooks = [ dict(type='MyHook', a=a_value, b=b_value, priority='NORMAL') ] ``` -------------------------------- ### Initialize MOT Model for Inference Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Demonstrates how to load a configuration file and initialize a DeepSORT model for multi-object tracking using the MMTracking API. ```python import mmcv import tempfile from mmtrack.apis import inference_mot, init_model mot_config = './configs/mot/deepsort/deepsort_faster-rcnn_fpn_4e_mot17-private-half.py' input_video = './demo/demo.mp4' imgs = mmcv.VideoReader(input_video) # build the model from a config file mot_model = init_model(mot_config, device='cuda:0') prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name ``` -------------------------------- ### Collect Environment Information with MMCV Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb This snippet uses the `collect_env` function from MMCV to gather detailed information about the current environment, including CUDA availability, compiler versions, and installed library versions. This is crucial for debugging and ensuring compatibility. ```python from mmcv import collect_env collect_env() ``` -------------------------------- ### Download MMTracking Model Checkpoints Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Uses shell commands to create a local directory and download pre-trained model weights for various tracking tasks including VID, SOT, and VIS from the OpenMMLab repository. ```bash !mkdir checkpoints !wget -c https://download.openmmlab.com/mmtracking/vid/selsa/selsa_faster_rcnn_r50_dc5_1x_imagenetvid/selsa_faster_rcnn_r50_dc5_1x_imagenetvid_20201227_204835-2f5a4952.pth -P ./checkpoints !wget -c https://download.openmmlab.com/mmtracking/sot/siamese_rpn/siamese_rpn_r50_1x_lasot/siamese_rpn_r50_1x_lasot_20211203_151612-da4b3c66.pth -P ./checkpoints !wget -c https://download.openmmlab.com/mmtracking/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019/masktrack_rcnn_r50_fpn_12e_youtubevis2019_20211022_194830-6ca6b91e.pth -P ./checkpoints ``` -------------------------------- ### Perform Video Object Detection Inference Source: https://context7.com/open-mmlab/mmtracking/llms.txt Demonstrates how to initialize a VID model and process video frames using temporal feature aggregation. It includes setting up a reference image sampler and visualizing detection results. ```python from mmtrack.apis import init_model, inference_vid import mmcv model = init_model( config='configs/vid/selsa/selsa_faster_rcnn_r101_dc5_1x_imagenetvid.py', checkpoint='checkpoints/selsa_faster_rcnn_r101.pth', device='cuda:0' ) ref_img_sampler = dict( frame_stride=10, num_left_ref_imgs=10 ) video_reader = mmcv.VideoReader('demo/video.mp4') for frame_id, frame in enumerate(video_reader): result = inference_vid( model=model, image=frame, frame_id=frame_id, ref_img_sampler=ref_img_sampler ) model.show_result( frame, result, score_thr=0.5, show=False, out_file=f'vid_output/{frame_id:06d}.jpg', thickness=2 ) ``` -------------------------------- ### Implement and Register Custom Optimizer in MMTracking Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_runtime.md Provides a guide on creating and registering a custom optimizer in MMTracking. It involves defining the optimizer class in a Python file, importing it into the registry either via '__init__.py' or 'custom_imports' in the config, and then specifying it in the config file's 'optimizer' field. ```python from torch.optim import Optimizer from mmcv.runner.optimizer import OPTIMIZERS @OPTIMIZERS.register_module() class MyOptimizer(Optimizer): def __init__(self, a, b, c): ``` ```python from .my_optimizer import MyOptimizer ``` ```python custom_imports = dict(imports=['mmtrack.core.optimizer.my_optimizer.py'], allow_failed_imports=False) ``` ```python optimizer = dict(type='MyOptimizer', a=a_value, b=b_value, c=c_value) ``` -------------------------------- ### Define and Register a Custom Tracker Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_mot_model.md Demonstrates how to create a custom tracker by inheriting from BaseTracker and registering it with the TRACKERS module. ```python from mmtrack.models import TRACKERS from .base_tracker import BaseTracker @TRACKERS.register_module() class MyTracker(BaseTracker): def __init__(self, arg1, arg2, *args, **kwargs): super().__init__(*args, **kwargs) pass def track(self, inputs): pass ``` -------------------------------- ### Testing and Evaluating Models in MMTracking Source: https://context7.com/open-mmlab/mmtracking/llms.txt Illustrates how to test and evaluate tracking models using MMTracking's command-line interface. Supports single-GPU and multi-GPU testing, with options for different evaluation metrics and checkpoint usage. ```python python tools/test.py \ configs/mot/tracktor/tracktor_faster-rcnn_r50_fpn_4e_mot17-public-half.py \ --eval track ``` ```python python tools/test.py \ configs/vid/dff/dff_faster_rcnn_r101_dc5_1x_imagenetvid.py \ --checkpoint checkpoints/dff_faster_rcnn_r101.pth \ --out results.pkl \ --eval bbox ``` ```python python tools/test.py \ configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py \ --checkpoint checkpoints/siamese_rpn_r50_lasot.pth \ --out results.pkl \ --eval track ``` ```bash ./tools/dist_test.sh \ configs/mot/bytetrack/bytetrack_yolox_x_crowdhuman_mot17-private-half.py 8 \ --eval track ``` ```python python tools/test.py \ configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py \ --checkpoint checkpoints/masktrack_rcnn_r50.pth \ --out results.pkl \ --format-only \ --eval-options resfile_path=./submission ``` -------------------------------- ### Train and Test Custom Models Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md General commands for training a new model using a custom configuration file and testing the resulting model with specific evaluation metrics. ```shell python tools/train.py ${NEW_CONFIG_FILE} python tools/test.py ${NEW_CONFIG_FILE} ${TRAINED_MODEL} --eval bbox track ``` -------------------------------- ### Train Model on Single GPU Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md This shell command initiates the training process for a specified configuration file on a single GPU. The training logs and model checkpoints are saved to a working directory, which can be defined in the configuration file or provided as a command-line argument using `--work-dir`. ```shell python tools/train.py ${CONFIG_FILE} [optional arguments] ``` -------------------------------- ### Build MMTrack Serve Docker Image Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/useful_tools_scripts.md Builds the Docker image required for serving MMTracking models. ```shell docker build -t mmtrack-serve:latest docker/serve/ ``` -------------------------------- ### Implement Custom Training Hook Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_runtime.md Demonstrates how to create a custom hook by inheriting from the base Hook class and registering it with the HOOKS registry. Users can define logic for various training stages. ```python from mmcv.runner import HOOKS, Hook @HOOKS.register_module() class MyHook(Hook): def __init__(self, a, b): pass def before_run(self, runner): pass def after_run(self, runner): pass def before_epoch(self, runner): pass def after_epoch(self, runner): pass def before_iter(self, runner): pass def after_iter(self, runner): pass ``` -------------------------------- ### Initialize and Run Single Object Tracking (SOT) Model Source: https://github.com/open-mmlab/mmtracking/blob/master/demo/MMTracking_Tutorial.ipynb Initializes a single object tracking model using a specified configuration and checkpoint. It reads frames from a video, performs SOT inference using an initial bounding box, visualizes the results on each frame, and compiles the results into an output video. Requires mmcv and tempfile. ```python sot_config = './configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py' sot_checkpoint = './checkpoints/siamese_rpn_r50_1x_lasot_20211203_151612-da4b3c66.pth' # build the model from a config file and a checkpoint file sot_model = init_model(sot_config, sot_checkpoint, device='cuda:0') init_bbox = [371, 411, 450, 646] imgs = mmcv.VideoReader(input_video) prog_bar = mmcv.ProgressBar(len(imgs)) out_dir = tempfile.TemporaryDirectory() out_path = out_dir.name for i, img in enumerate(imgs): result = inference_sot(sot_model, img, init_bbox, frame_id=i) sot_model.show_result( img, result, wait_time=int(1000. / imgs.fps), out_file=f'{out_path}/{i:06d}.jpg') prog_bar.update() output = './demo/sot.mp4' print(f'\n making the output video at {output} with a FPS of {imgs.fps}') mmcv.frames2video(out_path, output, fps=imgs.fps, fourcc='mp4v') out_dir.cleanup() ``` -------------------------------- ### Train Tracking Models via CLI Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/quick_run.md Standard command-line interface commands to initiate distributed training for MOT, SOT, and VIS models using specific configuration files. ```shell bash ./tools/dist_train.sh ./configs/det/faster-rcnn_r50_fpn_4e_mot17-half.py 8 --work-dir ./work_dirs/ bash ./tools/dist_train.sh ./configs/reid/resnet50_b32x8_MOT17.py 8 --work-dir ./work_dirs/ bash ./tools/dist_train.sh ./configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py 8 --work-dir ./work_dirs/ bash ./tools/dist_train.sh ./configs/vis/masktrack_rcnn/masktrack_rcnn_r50_fpn_12e_youtubevis2019.py 8 --work-dir ./work_dirs/ ``` -------------------------------- ### Define MMTracking Training and Logging Parameters Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/zh_cn/tutorials/config_mot.md Sets up the training environment including optimizer settings, learning rate schedules, and logging hooks for Tensorboard and Wandb. It also configures the evaluation metrics used to monitor model performance during training. ```python optimizer = dict(type='SGD', lr=0.02, momentum=0.9, weight_decay=0.0001) log_config = dict( interval=50, hooks=[ dict(type='TextLoggerHook', by_epoch=False), dict(type='TensorboardLoggerHook', by_epoch=False), dict(type='WandbLoggerHook', by_epoch=False, init_kwargs={'entity': "OpenMMLab", 'project': "MMTracking", 'config': cfg_dict}), ]) lr_config = dict( policy='step', warmup='linear', warmup_iters=100, warmup_ratio=0.01, step=[3]) evaluation = dict(metric=['bbox', 'track'], interval=1) ``` -------------------------------- ### Define and Register a Custom ReID Model Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_mot_model.md Illustrates how to create a custom ReID model by inheriting from BaseModule and registering it with the REID builder. ```python from mmcv.runner import BaseModule from ..builder import REID @REID.register_module() class MyReID(BaseModule): def __init__(self, arg1, arg2): pass def forward(self, inputs): pass ``` -------------------------------- ### Configure ByteTrack Multi-Object Tracker Source: https://context7.com/open-mmlab/mmtracking/llms.txt Provides a configuration structure for the ByteTrack algorithm, including detector settings, Kalman filter motion model, and tracker parameters for object association. ```python model = dict( type='ByteTrack', detector=dict( input_size=(800, 1440), bbox_head=dict(num_classes=1), test_cfg=dict(score_thr=0.01, nms=dict(type='nms', iou_threshold=0.7)) ), motion=dict(type='KalmanFilter'), tracker=dict( type='ByteTracker', obj_score_thrs=dict(high=0.6, low=0.1), init_track_thr=0.7, weight_iou_with_det_scores=True, match_iou_thrs=dict(high=0.1, low=0.5, tentative=0.3), num_frames_retain=30 ) ) ``` -------------------------------- ### Define and Register a Custom Backbone Source: https://github.com/open-mmlab/mmtracking/blob/master/docs/en/tutorials/customize_sot_model.md Demonstrates how to create a new backbone class by inheriting from BaseModule and using the @BACKBONES.register_module decorator. This allows the component to be dynamically loaded via configuration files. ```python import torch.nn as nn from mmcv.runner import BaseModule from mmdet.models.builder import BACKBONES @BACKBONES.register_module() class MobileNet(BaseModule): def __init__(self, arg1, arg2, *args, **kwargs): pass def forward(self, x): pass ```