JunweiLiang/Object_Detection_Tracking
Out-of-the-box code and models for CMU's object detection and tracking system for surveillance videos. Speed optimized Faster-RCNN model. Tensorflow based. Also supports EfficientDet. WACVW'20
repo name | JunweiLiang/Object_Detection_Tracking |
repo link | https://github.com/JunweiLiang/Object_Detection_Tracking |
homepage | |
language | Python |
size (curr.) | 8352 kB |
stars (curr.) | 164 |
created | 2019-05-26 |
license | Apache License 2.0 |
CMU Object Detection & Tracking for Surveillance Video Activity Detection
This repository contains the code and models for object detection and tracking from the CMU DIVA system. Our system (INF & MUDSML) achieves the best performance on the ActEv leaderboard (Cached).
If you find this code useful in your research then please cite
@inproceedings{chen2019minding,
title={Minding the Gaps in a Video Action Analysis Pipeline},
author={Chen, Jia and Liu, Jiang and Liang, Junwei and Hu, Ting-Yao and Ke, Wei and Barrios, Wayner and Huang, Dong and Hauptmann, Alexander G},
booktitle={2019 IEEE Winter Applications of Computer Vision Workshops (WACVW)},
pages={41--46},
year={2019},
organization={IEEE}
}
@inproceedings{liu2020wacv,
author = {Liu, Wenhe and Kang, Guoliang and Huang, Po-Yao and Chang, Xiaojun and Qian, Yijun and Liang, Junwei and Gui, Liangke and Wen, Jing and Chen, Peng},
title = {Argus: Efficient Activity Detection System for Extended Video Analysis},
booktitle = {The IEEE Winter Conference on Applications of Computer Vision (WACV) Workshops},
month = {March},
year = {2020}
}
Introduction
We utilize state-of-the-art object detection and tracking algorithm in surveillance videos. Our best object detection model basically uses Faster RCNN with a backbone of Resnet-101 with dilated CNN and FPN. The tracking algo (Deep SORT) uses ROI features from the object detection model. The ActEV trained models are good for small object detection in outdoor scenes. For indoor cameras, COCO trained models are better.
Updates
-
[10/2020] Added experiments comparing EfficientDet and MaskRCNN on VIRAT and AVA-Kinetics here.
-
[05/2020] Added EfficientDet (CVPR 2020) for inferencing. The D7 model is reported to be more than 12 mAP better than the Resnet-50 FPN model we used. Modified to be more efficient and tested with Python 2 & 3 and TF 1.15. See example commands and notes here.
-
[02/2020] We used Resnet-50 FPN model trained on MS-COCO for MEVA activity detection and got a competitive pAUDC of 0.49 on the leaderboard with a total processing speed of 0.64x real-time on a 4-GPU machine. The object detection module’s processing speed is about 0.125x real-time. [Frozen Model] [Example Command]
-
[01/2020] We discovered a problem with using OpenCV to extract frames for avi videos. Some avi videos have duplicate frames that are not physically presented in the files but only text instructions to duplicate previous frames. The problem is that OpenCV skip these frames without warning according to this bug report and here. Therefore with OpenCV you may get fewer frames which causes the frame index of detection results to be incorrect. Solution: 1. convert the avi videos to mp4 format; 2. use MoviePy or PyAV loader but they are 10% ~ 30% slower than OpenCV frame extraction. See
obj_detect_tracking.py
for implementation.
Dependencies
The latest inferencing code is tested with Tensorflow==1.15 and Python 2/3.
Other dependencies: numpy; scipy; sklearn; cv2; matplotlib; pycocotools
Code Overview
obj_detect_tracking.py
: Inference code for object detection & tracking.models.py
: Main model definition.nn.py
: Some layer definitions.main.py
: Code I used for training and testing experiments.eval.py
: Code I used for getting mAP/mAR.vis_json.py
: visualize the json outputs.get_frames_resize.py
: code for extracting frames from videos.utils.py
: some helper classes like getting moving average of losses and GPU usage.
Inferencing
- First download some test videos and the v3 model (v4-v6 models are un-verified models as we don’t have a test set with ground truth):
$ wget https://aladdin-eax.inf.cs.cmu.edu/shares/diva_obj_detect_models/models/v1-val_testvideos.tgz
$ tar -zxvf v1-val_testvideos.tgz
$ ls v1-val_testvideos > v1-val_testvideos.lst
$ wget https://aladdin-eax.inf.cs.cmu.edu/shares/diva_obj_detect_models/models/obj_v3_model.tgz
$ tar -zxvf obj_v3_model.tgz
- Run object detection & tracking on the test videos
$ python obj_detect_tracking.py --model_path obj_v3_model --version 3 --video_dir v1-val_testvideos \
--video_lst_file v1-val_testvideos.lst --frame_gap 1 --get_tracking \
--tracking_dir test_track_out
To have the object detection output in COCO json format, add --out_dir test_json_out
; To have the bounding box visualization, add --visualize --vis_path test_vis_out
.
To speed it up, try --frame_gap 8
, and the tracks between detection frames will be linearly interpolated.
The tracking results will be in test_track_out/
and in MOTChallenge format.
To run with EfficientDet models, download checkpoint from the official repo or my-d0-snapshot. Then run with --is_efficientdet
and --efficientdet_modelname efficientdet-d0
.
To visualize the tracking results:
# Put "Person/Vehicle" tracks visualization into the same video
$ ls $PWD/v1-val_testvideos/* > v1-val_testvideos.abs.lst
$ python get_frames_resize.py v1-val_testvideos.abs.lst v1-val_testvideos_frames/ --use_2level
$ python tracks_to_json.py test_track_out/ v1-val_testvideos.abs.lst test_track_out_json
$ python vis_json.py v1-val_testvideos.abs.lst v1-val_testvideos_frames/ test_track_out_json/ test_track_out_vis
# then use ffmpeg to make videos
$ ffmpeg -framerate 30 -i test_track_out_vis/VIRAT_S_000205_05_001092_001124/VIRAT_S_000205_05_001092_001124_F_%08d.jpg vis_video.mp4
Now you have the tracking visualization videos for both “Person” and “Vehicle” class.
-
You can also run inferencing with frozen graph (See this for instructions of how to pack the model). Change
--model_path obj_v3.pb
and add--is_load_from_pb
. It is about 30% faster. For running on MEVA dataset (avi videos & indoor scenes) or with EfficientDet models, see examples here. -
You can also run object detection on a list of images. Suppose you have a file list
imgs.lst
with absolute paths to images. Run with COCO trained MaskRCNN model:
# get model from Tensorpack
$ wget http://models.tensorpack.com/FasterRCNN/COCO-MaskRCNN-R101FPN1x.npz
$ python obj_detect_imgs.py --model_path COCO-MaskRCNN-R101FPN1x.npz --version 2 \
--img_lst imgs.lst --out_dir detection_out_maskrcnn --max_size 480 \
--short_edge_size 320 --is_coco_model --visualize --vis_path detection_vis_maskrcnn
Adjust the image input size as you wish. Run with COCO trained EfficientDet model:
$ https://storage.googleapis.com/cloud-tpu-checkpoints/efficientdet/coco/efficientdet-d0.tar.gz; tar -zxvf efficientdet-d0.tar.gz
$ python obj_detect_imgs.py --model_path efficientdet-d0/ --version 2 \
--is_efficientdet --efficientdet_modelname efficientdet-d0 --img_lst imgs.lst \
--out_dir detection_out_d0 --max_size 480 --short_edge_size 320 --is_coco_model \
--visualize --vis_path detection_vis_d0
Models
These are the models you can use for inferencing. The original ActEv annotations can be downloaded from here. I will add instruction for training and testing if requested. Click to download each model.
Activity Box Experiments:
Training & Testing
Instruction to train a new object detection model is here.
Training & Testing (Activity Box)
Instruction to train a new frame-level activity detection model is here.
Speed Optimization
TL;DR:
- TF v1.10 -> v1.13 (CUDA 9 & cuDNN v7.1 -> CUDA 10 & cuDNN v7.4) ~ +9% faster
- Use frozen graph ~ +30% faster
- Use TensorRT (FP32/FP16) optimized graph ~ +0% faster
- Use TensorRT (INT8) optimized graph ?
Experiments are recorded here.
Other things I have tried
These are my experiences with working on this surveillance dataset:
- FPN provides significant improvement over non-FPN backbone;
- Dilated CNN in backbone also helps but Squeeze-Excitation block is unclear (see model obj_v6);
- Deformable CNN in backbone seems to achieve same improvement as dilated CNN but my implementation is way too slow.
- Cascade RCNN doesn’t help (IOU=0.5). I’m using IOU=0.5 in my evaluation since the original annotations are not “tight” bounding boxes.
- Decoupled RCNN (using a separate Resnet-101 for box classification) slightly improves AP (Person: 0.836 -> 0.837) but takes 7x more time.
- SoftNMS shows mixed results and add 5% more computation time to system (since I used the CPU version). So I don’t use it.
- Tried Mix-up by randomly mixing ground truth bounding boxes from different frames. Doesn’t improve performance.
- Focal loss doesn’t help.
- Relation Network does not improve and the model is huge (my implementation).
- ResNeXt does not see significant improvement on this dataset.
TODO
- Use Python Queue and a separate thread for frame extraction
- Make batch_size > 1 for inferencing
Acknowledgements
I made this code by studying the nice example in Tensorpack.