qfgaohao / pytorch-ssd

MobileNetV1, MobileNetV2, VGG based SSD/SSD-lite implementation in Pytorch 1.0 / Pytorch 0.4. Out-of-box support for retraining on Open Images dataset. ONNX and Caffe2 support. Experiment Ideas like CoordConv.
https://medium.com/@smallfishbigsea/understand-ssd-and-implement-your-own-caa3232cd6ad
MIT License
1.39k stars 529 forks source link

MobileNetv2 enchancement #14

Open lucasjinreal opened 5 years ago

lucasjinreal commented 5 years ago

Thanks for sharing this wonderful project, however, I just wonder if there is any plan to add support of mobilenetv2 backend support SSD? if so, I can provide you a simple MobileNetv2 net scripts in pytorch.

qfgaohao commented 5 years ago

Thanks @jinfagang . I had a brief look at your implementation. They are very impressive! I am happy to integrate. Have you got some benchmark results of your MobileNetv2 or SSD models? So we can quickly get started.

Btw, there is a hacky mobilenetV2 SSD Lite impl https://github.com/qfgaohao/pytorch-ssd/blob/squeezenet-ssd-lite/vision/ssd/mobilenet_v2_ssd_lite.py . The problem I am facing is that ONNX doesn't support Relu6 used in Mobilenetv2. I replaced it with Relu. Currently I am training MobileNetv2 Imagenet Models.

I assume the ONNX Relu6 problem will resolve over time.

lucasjinreal commented 5 years ago

@qfgaohao That is the question, I just borrowed some codes from others, change it into pytorch 0.41 fully supported, but after I test it, just not got any results (seems the whole process of SSD was broken). But the backends that MobilenetV2 works fine.

theoretically, mobilenetv2 should be faster than mobilenetv1 backend, at least should be more accurate.

Now that you already training MobileNetV2 on imagenet, I can help you training on other datasets.

I think ReLu6 should not be the problem, if ONNX not support it now, we can just skip it at now time, hopefully ONNX will support it in the near future

qfgaohao commented 5 years ago

Hi @jinfagang you are right, we can safely skip Relu6. I will merge the code next week. I will let you how it goes.

lucasjinreal commented 5 years ago

@qfgaohao Sounds great! Waiting for you response!

qfgaohao commented 5 years ago

@jinfagang Sorry for the delay. I was occupied by an urgent project. Plz see the trained MobleNetV2 SSD-Lite model with mp 0.686. https://storage.googleapis.com/models-hao/mb2-ssd-lite-mp-0_686.pth .

I have merged the code into the master branch. Here is code is reproduce the model.

wget -P models https://storage.googleapis.com/models-hao/mb2-imagenet-71_8.pth
python train_ssd.py --dataset_type voc  --datasets ~/data/VOC0712/VOC2007 ~/data/VOC0712/VOC2012 --validation_dataset ~/data/VOC0712/test/VOC2007/ --net mb2-ssd-lite --base_net models/mb2-imagenet-71_8.pth  --scheduler cosine --lr 0.01 --t_max 200 --validation_epochs 5 --num_epochs 20

I haven't got a MobileNetV2 with Relu base net having a reasonable accuracy. So the above model is based on the original MobileNetV2. The pre-trained base net is from https://github.com/tonylins/pytorch-mobilenet-v2