Git Product home page Git Product logo

microsoft / fairmot Goto Github PK

View Code? Open in Web Editor NEW
156.0 12.0 20.0 43.5 MB

This project provides an official implementation of our recent work on real-time multi-object tracking in videos. The previous works conduct object detection and tracking with two separate models so they are very slow. In contrast, we propose a one-stage solution which does detection and tracking with a single network by elegantly solving the alignment problem. The resulting approach achieves groundbreaking results in terms of both accuracy and speed: (1) it ranks first among all the trackers on the MOT challenges; (2) it is significantly faster than the previous state-of-the-arts. In addition, it scales gracefully to handle a large number of objects.

License: MIT License

Shell 0.22% Python 80.36% Dockerfile 0.80% C++ 3.94% Cuda 13.22% C 1.47%

fairmot's Introduction

FairMOT

This is the official implementation for:

A Simple Baseline for Multi-Object Tracking,
Yifu Zhang, Chunyu Wang, Xinggang Wang, Wenjun Zeng, Wenyu Liu,
arXiv technical report (arXiv 2004.01888)

Abstract

There has been remarkable progress on object detection and association in recent years which are the core components for multi-object tracking. However, little attention has been focused on accomplishing the two tasks in a single network to improve the inference speed. The initial attempts along this path ended up with degraded results mainly because the association branch is not appropriately learned. In this work, we study the essential reasons behind the failure, and accordingly present a simple baseline to addresses the problems. It remarkably outperforms the state-of-the-arts on the MOT challenge datasets at 30 FPS. We hope this baseline could inspire and help evaluate new ideas in this field.

Tracking performance

Results on MOT challenge test set

Dataset MOTA IDF1 IDS MT ML FPS
2DMOT15 59.0 62.2 582 45.6% 11.5% 30.5
MOT16 68.7 70.4 953 39.5% 19.0% 25.9
MOT17 67.5 69.8 2868 37.7% 20.8% 25.9
MOT20 58.7 63.7 6013 66.3% 8.5% 13.2

All of the results are obtained on the MOT challenge evaluation server under the “private detector” protocol. We rank first among all the trackers on 2DMOT15, MOT17 and the recently released (2020.02.29) MOT20. Note that our IDF1 score remarkably outperforms other one-shot MOT trackers by more than 10 points. The tracking speed of the entire system can reach up to 30 FPS.

Video demos on MOT challenge test set

Installation

  • Clone this repo, and we'll call the directory that you cloned as ${FAIRMOT_ROOT}
  • Install dependencies. We use python 3.7 and pytorch >= 1.2.0
conda create -n FairMOT
conda activate FairMOT
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch
cd ${FAIRMOT_ROOT}
pip install -r requirements.txt
cd src/lib/models/networks/DCNv2 sh make.sh
  • We use DCNv2 in our backbone network and more details can be found in their repo.
  • In order to run the code for demos, you also need to install ffmpeg.

Data preparation

We use the same training data as JDE. Please refer to their DATA ZOO to download and prepare all the training data including Caltech Pedestrian, CityPersons, CUHK-SYSU, PRW, ETHZ, MOT17 and MOT16.

2DMOT15 and MOT20 can be downloaded from the official webpage of MOT challenge. After downloading, you should prepare the data in the following structure:

MOT15
   |——————images
   |        └——————train
   |        └——————test
   └——————labels_with_ids
            └——————train(empty)
MOT20
   |——————images
   |        └——————train
   |        └——————test
   └——————labels_with_ids
            └——————train(empty)

Then, you can change the seq_root and label_root in src/gen_labels_15.py and src/gen_labels_20.py and run:

cd src
python gen_labels_15.py
python gen_labels_20.py

to generate the labels of 2DMOT15 and MOT20. The seqinfo.ini files of 2DMOT15 can be downloaded here [Google], [Baidu],code:8o0w.

Pretrained models and baseline model

  • Pretrained models

DLA-34 COCO pretrained model: DLA-34 official. HRNetV2 ImageNet pretrained model: HRNetV2-W18 official, HRNetV2-W32 official. After downloading, you should put the pretrained models in the following structure:

${FAIRMOT_ROOT}
   └——————models
           └——————ctdet_coco_dla_2x.pth
           └——————hrnetv2_w32_imagenet_pretrained.pth
           └——————hrnetv2_w18_imagenet_pretrained.pth
  • Baseline model

Our baseline FairMOT model can be downloaded here: DLA-34: [Google] [Baidu, code: 88yn]. HRNetV2_W18: [Google] [Baidu, code: 7jb1]. After downloading, you should put the baseline model in the following structure:

${FAIRMOT_ROOT}
   └——————models
           └——————all_dla34.pth
           └——————all_hrnet_v2_w18.pth
           └——————...

Training

  • Download the training data
  • Change the dataset root directory 'root' in src/lib/cfg/data.json and 'data_dir' in src/lib/opts.py
  • Run:
sh experiments/all_dla34.sh

Tracking

  • The default settings run tracking on the validation dataset from 2DMOT15. You can run:
cd src
python track.py mot --load_model ../models/all_dla34.pth --conf_thres 0.6

to see the tracking results. You can also set save_images=True in src/track.py to save the visualization results of each frame.

  • To get the txt results of the test set of MOT16 or MOT17, you can run:
cd src
python track.py mot --test_mot17 True --load_model ../models/all_dla34.pth --conf_thres 0.4
python track.py mot --test_mot16 True --load_model ../models/all_dla34.pth --conf_thres 0.4

and send the txt files to the MOT challenge evaluation server to get the results.

  • To get the SOTA results of 2DMOT15 and MOT20, you need to finetune the baseline model on the specific dataset because our training set do not contain them. You can run:
sh experiments/ft_mot15_dla34.sh
sh experiments/ft_mot20_dla34.sh

and then run the tracking code:

cd src
python track.py mot --test_mot15 True --load_model your_mot15_model.pth --conf_thres 0.3
python track.py mot --test_mot20 True --load_model your_mot20_model.pth --conf_thres 0.3

Results of the test set all need to be evaluated on the MOT challenge server. You can see the tracking results on the training set by setting --val_motxx True and run the tracking code. We set 'conf_thres' 0.4 for MOT16 and MOT17. We set 'conf_thres' 0.3 for 2DMOT15 and MOT20.

Demo

You can input a raw video and get the demo video by running src/demo.py and get the mp4 format of the demo video:

cd src
python demo.py mot --load_model ../models/all_dla34.pth --conf_thres 0.4

You can change --input-video and --output-root to get the demos of your own videos.

If you have difficulty building DCNv2 and thus cannot use the DLA-34 baseline model, you can run the demo with the HRNetV2_w18 baseline model:

cd src
python demo.py mot --load_model ../models/all_hrnet_v2_w18.pth --arch hrnet_18 --reid_dim 128 --conf_thres 0.4

--conf_thres can be set from 0.3 to 0.7 depending on your own videos.

Citation

@article{zhang2020simple,
  title={A Simple Baseline for Multi-Object Tracking},
  author={Zhang, Yifu and Wang, Chunyu and Wang, Xinggang and Zeng, Wenjun and Liu, Wenyu},
  journal={arXiv preprint arXiv:2004.01888},
  year={2020}
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

fairmot's People

Contributors

chunyuwang avatar microsoft-github-operations[bot] avatar microsoftopensource avatar wangchunyupku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fairmot's Issues

kalman init

why the init of kalman filter's std is:
std = [
2 * self._std_weight_position * measurement[3],
2 * self._std_weight_position * measurement[3],
1e-2,
2 * self._std_weight_position * measurement[3],
10 * self._std_weight_velocity * measurement[3],
10 * self._std_weight_velocity * measurement[3],
1e-5,
10 * self._std_weight_velocity * measurement[3]]

could you tell some reason or source ?

Update 2DMOT15 references to MOT15 and fix broken link

While reviewing the documentation, I noticed references to the "2DMOT15" dataset. I've come to understand that the official name of the dataset has recently been changed from "2DMOT15" to "MOT15".

However, some parts of the documentation still refer to it as "2DMOT15". Given the previous experiments and references conducted with "2DMOT15", changing the name throughout might introduce confusion. Therefore, instead of altering the dataset name in the documentation, it seems more prudent to just update the broken link to prevent any confusion.

Proposed changes:

  • Only fix the broken link that points to the 2DMOT15 dataset.

P.S. I plan to work on this issue and submit a PR soon.

pre-trained hrnet not available

Thanks for releasing the code and sharing pre-trained models.
However, the link of the pre-trained HRNet is invalid. Could you kindly check the status of the download link?

KeyError: 'epoch' on running track.py with hrnetv2_w32_imagenet_pretrained.pth

Hello,
I want to use the code with pretrained imagenet weights: hrnetv2_w32_imagenet_pretrained.pth ( given as the official fairmot implementation on imagenet dataset). However, running the command:

python track.py mot --load_model /content/FairMOT/models/hrnetv2_w32_imagenet_pretrained.pth --conf_thres 0.4 --data_dir /content/FairMOT --val_mot20 VAL_MOT20

gives me the following error:

Fix size testing.
training chunk_sizes: [6, 6]
The output will be saved to  /content/FairMOT/src/lib/../../exp/mot/default
heads {'hm': 1, 'wh': 2, 'id': 512, 'reg': 2}
2021-10-11 05:01:30 [INFO]: start seq: MOT20-01
Creating model...
Traceback (most recent call last):
  File "track.py", line 240, in <module>
    save_videos=False)
  File "track.py", line 112, in main
    save_dir=output_dir, show_image=show_image, frame_rate=frame_rate)
  File "track.py", line 56, in eval_seq
    tracker = JDETracker(opt, frame_rate=frame_rate)
  File "/content/FairMOT/src/lib/tracker/multitracker.py", line 181, in __init__
    self.model = load_model(self.model, opt.load_model)
  File "/content/FairMOT/src/lib/models/model.py", line 37, in load_model
    print('loaded {}, epoch {}'.format(model_path, checkpoint['epoch']))
KeyError: 'epoch'

Any help will be appreciated. Thank you

I got ValueError: cannot reshape array of size 20 into shape (6) when I started custom training. What you think?

!sh /content/FairMOT/experiments/all_dla34.sh
#!sh /content/FairMOT/experiments/ft_mot15_dla34.sh
/content/FairMOT/experiments/all_dla34.sh: 1: cd: can't cd to src
Using tensorboardX
Fix size testing.
training chunk_sizes: [8]
The output will be saved to /content/FairMOT/src/lib/../../exp/mot/all_dla34
Setting up data...

dataset summary
OrderedDict([('safety', 1.9113280000000001)])
total # identities: 2
start index
OrderedDict([('safety', 0)])

heads {'hm': 1, 'wh': 2, 'id': 512, 'reg': 2}
Namespace(K=128, arch='dla_34', batch_size=8, cat_spec_wh=False, chunk_sizes=[8], conf_thres=0.6, data_cfg='/content/FairMOT/src/lib/cfg/data.json', data_dir='/data/yfzhang/MOT/JDE', dataset='jde', debug_dir='/content/FairMOT/src/lib/../../exp/mot/all_dla34/debug', dense_wh=False, det_thres=0.3, down_ratio=4, exp_dir='/content/FairMOT/src/lib/../../exp/mot', exp_id='all_dla34', fix_res=True, gpus=[0], gpus_str='0', head_conv=256, heads={'hm': 1, 'wh': 2, 'id': 512, 'reg': 2}, hide_data_time=False, hm_weight=1, id_loss='ce', id_weight=1, img_size=(1088, 608), input_h=1088, input_res=1088, input_video='../videos/MOT16-03.mp4', input_w=608, keep_res=False, load_model='/content/drive/MyDrive/fairmot_dla34.pth', lr=0.0001, lr_step=[20, 27], master_batch_size=8, mean=None, metric='loss', min_box_area=200, mse_loss=False, nID=2, nms_thres=0.4, norm_wh=False, not_cuda_benchmark=False, not_prefetch_test=False, not_reg_offset=False, num_classes=1, num_epochs=30, num_iters=-1, num_stacks=1, num_workers=8, off_weight=1, output_format='video', output_h=272, output_res=272, output_root='../results', output_w=152, pad=31, print_iter=0, reg_loss='l1', reg_offset=True, reid_dim=512, resume=False, root_dir='/content/FairMOT/src/lib/../..', save_all=False, save_dir='/content/FairMOT/src/lib/../../exp/mot/all_dla34', seed=317, std=None, task='mot', test=False, test_mot15=False, test_mot16=False, test_mot17=False, test_mot20=False, track_buffer=30, trainval=False, val_intervals=5, val_mot15=False, val_mot16=False, val_mot17=False, val_mot20=False, vis_thresh=0.5, wh_weight=0.1)
Creating model...
loaded /content/drive/MyDrive/fairmot_dla34.pth, epoch 30
Skip loading parameter wh.2.weight, required shapetorch.Size([2, 256, 1, 1]), loaded shapetorch.Size([4, 256, 1, 1]). If you see this, your model does not fully load the pre-trained weight. Please make sure you have correctly specified --arch xxx or set the correct --num_classes for your own dataset.
Skip loading parameter wh.2.bias, required shapetorch.Size([2]), loaded shapetorch.Size([4]). If you see this, your model does not fully load the pre-trained weight. Please make sure you have correctly specified --arch xxx or set the correct --num_classes for your own dataset.
Skip loading parameter id.2.weight, required shapetorch.Size([512, 256, 1, 1]), loaded shapetorch.Size([128, 256, 1, 1]). If you see this, your model does not fully load the pre-trained weight. Please make sure you have correctly specified --arch xxx or set the correct --num_classes for your own dataset.
Skip loading parameter id.2.bias, required shapetorch.Size([512]), loaded shapetorch.Size([128]). If you see this, your model does not fully load the pre-trained weight. Please make sure you have correctly specified --arch xxx or set the correct --num_classes for your own dataset.
Starting training...
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00211.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00211.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00481.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00481.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00076.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00076.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00661.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00661.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00931.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00931.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00811.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00811.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00556.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00556.txt
okay on image
/content/drive/MyDrive/safety-quipmentColab/images/val/z00766.jpg
/content/drive/MyDrive/safety-quipmentColab/labels_with_ids/val/z00766.txt
Traceback (most recent call last):
File "train.py", line 102, in
main(opt)
File "train.py", line 73, in main
log_dict_train, _ = trainer.train(epoch, train_loader)
File "/content/FairMOT/src/lib/trains/base_trainer.py", line 124, in train
return self.run_epoch('train', epoch, data_loader)
File "/content/FairMOT/src/lib/trains/base_trainer.py", line 67, in run_epoch
for iter_id, batch in enumerate(data_loader):
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 345, in next
data = self._next_data()
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 856, in _next_data
return self._process_data(data)
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataloader.py", line 881, in _process_data
data.reraise()
File "/usr/local/lib/python3.7/dist-packages/torch/_utils.py", line 394, in reraise
raise self.exc_type(msg)
ValueError: Caught ValueError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/content/FairMOT/src/lib/datasets/dataset/jde.py", line 427, in getitem
imgs, labels, img_path, (input_h, input_w) = self.get_data(img_path, label_path)
File "/content/FairMOT/src/lib/datasets/dataset/jde.py", line 194, in get_data
labels0 = np.loadtxt(label_path, dtype=np.float32).reshape(-1, 6)
ValueError: cannot reshape array of size 20 into shape (6)

Need help in figuring out the proper configuration for training

As mentioned in the readme,I have downloaded the MOT20 dataset and organized it as follows

MOT20
     images
         train
         test
     labels_with_ids
        train

Then inside gen_labels_20.py i have mentioned it as follows

seq_root = '/content/MOT20/train'
label_root = '/content/MOT20/labels_with_ids/train'

Then finally I changed the dataset directories as mentioned in

Change the dataset root directory 'root' in src/lib/cfg/data.json and 'data_dir' in src/lib/opts.py

the data.json looks like this


    "root":"/content/FairMOT/src/data",
    "train":
    {
        "mot20":"./data/mot20.train",
        
    },
    "test_emb":
    {
        "mot15":"./data/mot20.train"
    },
    "test":
    {
        "mot15":"./data/mot20.train"
    }

And in opts.py
the changes are as follows

self.parser.add_argument('--data_cfg', type=str,
                             default='../src/lib/cfg/data.json',
                             help='load data from cfg')
    self.parser.add_argument('--data_dir', type=str, default='/content/FairMOT/src/data')

On running I get the following error

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 7 column 5 (char 101)

Because I only want to train and test on mot20 and not on other datasets I removed the part about other datasets from data.json file
Furthermore should the data_dir be set to where MOT20 is or should it be set to data in src directory.The same applies in data.json

Will appreciate it if you could clarify

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.