All Projects → twangnh → Distilling Object Detectors

twangnh / Distilling Object Detectors

Licence: mit
Implementations of CVPR 2019 paper Distilling Object Detectors with Fine-grained Feature Imitation

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Distilling Object Detectors

Fpn tensorflow
This is a tensorflow re-implementation of Feature Pyramid Networks for Object Detection.
Stars: ✭ 291 (-8.2%)
Mutual labels:  object-detection
Jeelizar
JavaScript object detection lightweight library for augmented reality (WebXR demos included). It uses convolutional neural networks running on the GPU with WebGL.
Stars: ✭ 296 (-6.62%)
Mutual labels:  object-detection
Vott
Visual Object Tagging Tool: An electron app for building end to end Object Detection Models from Images and Videos.
Stars: ✭ 3,684 (+1062.15%)
Mutual labels:  object-detection
Autogluon
AutoGluon: AutoML for Text, Image, and Tabular Data
Stars: ✭ 3,920 (+1136.59%)
Mutual labels:  object-detection
Open3d Ml
An extension of Open3D to address 3D Machine Learning tasks
Stars: ✭ 284 (-10.41%)
Mutual labels:  object-detection
Yolo V2 Pytorch
YOLO for object detection tasks
Stars: ✭ 302 (-4.73%)
Mutual labels:  object-detection
Simple Faster Rcnn Pytorch
A simplified implemention of Faster R-CNN that replicate performance from origin paper
Stars: ✭ 3,422 (+979.5%)
Mutual labels:  object-detection
Pytorch Yolo V1
an experiment for yolo-v1, including training and testing.
Stars: ✭ 314 (-0.95%)
Mutual labels:  object-detection
Yolov3v4 Modelcompression Multidatasettraining Multibackbone
YOLO ModelCompression MultidatasetTraining
Stars: ✭ 287 (-9.46%)
Mutual labels:  object-detection
Deep Sort Yolov4
People detection and optional tracking with Tensorflow backend.
Stars: ✭ 306 (-3.47%)
Mutual labels:  object-detection
Pytorch Hardnet
35% faster than ResNet: Harmonic DenseNet, A low memory traffic network
Stars: ✭ 293 (-7.57%)
Mutual labels:  object-detection
Fastmot
High-performance multiple object tracking based on YOLO, Deep SORT, and optical flow
Stars: ✭ 284 (-10.41%)
Mutual labels:  object-detection
Keras Centernet
A Keras implementation of CenterNet with pre-trained model (unofficial)
Stars: ✭ 307 (-3.15%)
Mutual labels:  object-detection
Pytorch Yolo V3
A PyTorch implementation of the YOLO v3 object detection algorithm
Stars: ✭ 3,148 (+893.06%)
Mutual labels:  object-detection
Tide
A General Toolbox for Identifying Object Detection Errors
Stars: ✭ 309 (-2.52%)
Mutual labels:  object-detection
Lvis Api
Python API for LVIS Dataset
Stars: ✭ 290 (-8.52%)
Mutual labels:  object-detection
Haar.js
Feature Detection based on Haar Cascades in JavaScript (Viola-Jones-Lienhart et al Algorithm)
Stars: ✭ 301 (-5.05%)
Mutual labels:  object-detection
Finger Detection And Tracking
Finger Detection and Tracking using OpenCV and Python
Stars: ✭ 317 (+0%)
Mutual labels:  object-detection
Neural Pipeline
Neural networks training pipeline based on PyTorch
Stars: ✭ 315 (-0.63%)
Mutual labels:  object-detection
Alturos.yolo
C# Yolo Darknet Wrapper (real-time object detection)
Stars: ✭ 308 (-2.84%)
Mutual labels:  object-detection

Implementation of our CVPR 2019 paper Distilling Object Detectors with Fine-grained Feature Imitation

15% performance boost of student model

We have proposed a general distillation approach for anchor based object detection model to get enhanced small student model with the knowledge of large teacher model, which is othorgonal and can be further combined with other model compression method like quantization and pruning. The key observation of vanilla knowledge distillation technique is that the inter-class discrepancy of perdiction confidence reveals how curmbersome model tends to genearlize (e.g., how much confidence the model would put on cat label when the input is actually a dog). While our idea is the inter-location discrepancy of feature response near object also reveals how large detector tends to generalize (e.g., how is the model's response different for different near object anchor locations).

We release the code for distilling shufflenet based detector and VGG11 based Faster R-CNN, this code repository implements Faster R-CNN imitation based on pytorch-faster-rcnn. Check Distilling-ShuffleDet for tensorflow code of Shufflenet based detector imitation.

🔥Updating🔥

TODO

We have accumulated the following to-do list, which we hope to complete in the near future

  • Still to come:
    • [ ] Add more models(ResNet-FRCNN, FPN-FRCNN).
    • [ ] Implement SSD model distillation.

Distilling VGG11-FRCNN

pytorch 0.4.0 python2

Preparation

1 Clone the repository

First of all, clone the code

git clone https://github.com/twangnh/Distilling-Object-Detectors

Then, create a folder:

cd Distilling-Object-Detectors && mkdir data

2 Requirements and Compilation

pip install -r requirements.txt

Compile the cuda dependencies using following commands:

cd lib
sh make.sh

To use the .py file in 'lib', you should add the 'lib' to PYTHONPATH, so open bashrc and add the path to the bashrc file:

vim ~/.bashrc
export PYTHONPATH="${PYTHONPATH}:/the/lib/path/of/the/project"

After changing the bashrc file, update the bashrc by login again or directly update it by:

source ~/.bashrc

3 Data preparation

  • PASCAL_VOC 07+12: Please follow the instructions in py-faster-rcnn to prepare VOC datasets. Actually, you can refer to any others. After downloading the data, create softlinks in the folder data/. The prepaired direcoty is like data/VOCdevkit2007/VOC2007/...

4 download imagenet pretrained model and trained VGG16-FRCNN teacher model

download imagenet pretrained VGG11 model at GoogleDrive and put it into data/pretrained_model/

download trained VGG16-FRCNN model at GoogleDrive and put it into data/VGG16-FRCNN/

Train

currently only batch size of 1 is supported

python trainval_net_sup.py --dataset pascal_voc --net vgg11 --bs 1 --nw 2 --lr 3e-3 --lr_decay_step 5 --cuda --s 1 --gpu 0
[session 1][epoch  1][iter    0/10022] loss: 13.4238, loss_sup: 0.0000, lr: 3.00e-03
			fg/bg=(15/241), time cost: 0.307381
			rpn_cls: 0.7839, rpn_box: 0.4312, rcnn_cls: 12.0130, rcnn_box 0.1957 
[session 1][epoch  1][iter  100/10022] loss: 2.1172, loss_sup: 0.0000, lr: 3.00e-03
			fg/bg=(15/241), time cost: 17.871297
			rpn_cls: 0.2372, rpn_box: 0.0492, rcnn_cls: 0.5382, rcnn_box 0.1475 
[session 1][epoch  1][iter  200/10022] loss: 2.3993, loss_sup: 0.0000, lr: 3.00e-03
			fg/bg=(27/229), time cost: 17.885193
			rpn_cls: 0.0451, rpn_box: 0.3003, rcnn_cls: 2.5547, rcnn_box 0.5216 
[session 1][epoch  1][iter  300/10022] loss: 1.6754, loss_sup: 0.0000, lr: 3.00e-03
			fg/bg=(21/235), time cost: 17.856990
			rpn_cls: 0.2837, rpn_box: 0.2542, rcnn_cls: 1.1131, rcnn_box 0.2073 
[session 1][epoch  1][iter  400/10022] loss: 1.6178, loss_sup: 0.1145, lr: 3.00e-03
			fg/bg=(23/233), time cost: 17.976755
			rpn_cls: 0.3597, rpn_box: 0.0106, rcnn_cls: 0.7343, rcnn_box 0.2363 
[session 1][epoch  1][iter  500/10022] loss: 1.4362, loss_sup: 9.6434, lr: 3.00e-03
			fg/bg=(32/224), time cost: 17.911143
			rpn_cls: 0.1783, rpn_box: 0.0235, rcnn_cls: 0.4522, rcnn_box 0.3731 
[session 1][epoch  1][iter  600/10022] loss: 1.3638, loss_sup: 8.4568, lr: 3.00e-03
			fg/bg=(18/238), time cost: 18.024369
			rpn_cls: 0.4774, rpn_box: 0.1143, rcnn_cls: 0.4781, rcnn_box 0.1663 

training should progress as above, where loss_sup is the imitation loss and firts 400 steps are warmup steps with no imitation (i.e., loss_sup = 0.) models will be saved in ./temp/vgg11/pascal_voc/xxx.pth

Train without imitation (baseline training)

currently only batch size of 1 is supported

python trainval_net_sup.py --dataset pascal_voc --net vgg11 --bs 1 --nw 2 --lr 3e-3 --lr_decay_step 5 --cuda --s 1 --gpu 0 --tfi True

models will be saved in ./temp/vgg11/pascal_voc/xxx.pth Note the imitation loss weight and warm up step can be further tuned with --ilw and --ws

Test

python test_net.py --dataset pascal_voc --net vgg11 --checksession 1 --checkepoch 2 --checkpoint 10021 --cuda --gpu 0

change checksession, checkepoch, checkpoint to test specific model

model   #GPUs batch size learning_rate(lr) lr_decay max_epoch mAP ckpt
VGG-16     1 1 1e-3 5   7   70.1 GoogleDrive
VGG-11     1 4 3e-3 15   59.6 GoogleDrive
VGG-11-I    8 16 3e-3  8   15 67.6 +8.0 GoogleDrive

models at max_epoch are reported

the numbers are different from the paper as they are independent running of the algorithm.

Test with trained model

download the trained model at the GoogleDrive link, run

python test_net.py --dataset pascal_voc --net vgg11 --load_name ./path_to/xxx.pth --cuda --gpu 0

Distilling ShuffleDet

...

We have implemented a single layer one-stage toy object detector with tensorflow, and mutli-gpu training with cross-gpu batch normalization, check Distilling-ShuffleDet for codes

Models Flops
/G
Params
/M
car pedestrian cyclist mAP ckpt
Easy Mod Hard Easy Mod Hard Easy Mod Hard
1x 5.1 1.6 85.7 74.3 65.8 63.2 55.6 50.6 69.7 51.0 49.1 62.8 GoogleDrive
0.5x 1.5 0.53 81.6 71.7 61.2 59.4 52.3 45.5 59.7 43.5 42.0 57.4 GoogleDrive
0.5x-I 1.5 0.53 84.9 72.9 64.1 60.7 53.3 47.2 69.0 46.2 44.9 60.4 GoogleDrive
+3.3 +1.2 +2.9 +1.3 +1.0 +1.7 +9.3 +2.7 +2.9 +3.0
0.25x 0.67 0.21 67.2 56.6 47.5 54.7 48.4 42.1 49.1 33.3 32.9 48.0 GoogleDrive
0.25x-I 0.67 0.21 76.6 62.3 54.6 56.8 48.2 42.6 56.6 37.3 36.5 52.4 GoogleDrive
+9.4 +5.7 +7.1 +2.1 -0.2 +0.5 +7.5 +4.0 +3.6 +4.4

models with highest mAP are reported for both baseline and distilled model

Note the numbers are different from the paper as they are independent running of the algorithm and we have migrated from single GPU training to multi-gpu training with larger batch size.

Distilling YoloV2

Third party implementation of distilling YOLOV2 on Widerface(codes not available yet, but very easy to implement)

Model size easy medium hard
YOLOv2 190MB 87.2 74.6 36.0
0.25x 12MB 78.2 69.8 35.6
0.25x-I 12MB 83.9 +5.7 74.9 +5.1 38.5 +2.9
0.15x 4.4MB 69.7 61.1 29.7
0.15x-I 4.4MB 79.3 +9.6 67.0 +5.9 32.0 +2.3

Citation

@inproceedings{wang2019distilling,
  title={Distilling Object Detectors With Fine-Grained Feature Imitation},
  author={Wang, Tao and Yuan, Li and Zhang, Xiaopeng and Feng, Jiashi},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
  pages={4933--4942},
  year={2019}
}

License

The code and the models are MIT licensed, as found in the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].