chuanqi305 / MobileNet-SSD

Caffe implementation of Google MobileNet SSD detection network, with pretrained weights on VOC0712 and mAP=0.727.
MIT License
2.04k stars 1.18k forks source link

Convert tensorflow model to caffemodel #36

Open leon-liangwu opened 7 years ago

leon-liangwu commented 7 years ago

你好 传奇305,

能否分享一下你的这个脚本?

感激万分。

leon-liangwu commented 7 years ago

@chuanqi305

leon-liangwu commented 7 years ago

@chuanqi305 I tested your pretrained model on ImageNet dataset. I only got 0.42 accuracy. Why?

chuanqi305 commented 7 years ago

Because the 'Relu6', I replaced Relu6 by Relu layer.

chuanqi305 commented 7 years ago

@DreamHorse0301 The script is only for mobilenet, not a universal converting script.

leon-liangwu commented 7 years ago

@chuanqi305 Thanks. I've figured out how to convert mobilenet to caffemodel, and converted the 0.75 version. But I still have some concern that I change relu layer to make relu output smaller than 6 and the accuracy does not show any better.

chuanqi305 commented 7 years ago

@DreamHorse0301 There is a little difference about the 3x3 Convolution's 'pad' parameter. Here is the padding of tensorflow's mobilenet:

conv0:stride=2, output=150x150, pad=(0, 0, 1, 1)
conv1:stride=1, output=150x150, pad=(1, 1, 1, 1)
conv2:stride=2, output=75x75, pad=(0, 0, 1, 1)
conv3:stride=1, output=75x75, pad=(1, 1, 1, 1)
conv4:stride=2, output=38x38, pad=(1, 1, 1, 1)
conv5:stride=1, output=38x38, pad=(1, 1, 1, 1)
conv6:stride=2, output=19x19, pad=(0, 0, 1, 1)
conv7:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv8:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv9:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv10:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv11:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv12:stride=2, output=10x10, pad=(1, 1, 1, 1)
conv13:stride=1, output=10x10, pad=(1, 1, 1, 1)

But in caffe, the padding of left,top,right,bottom must be the same. So the padding is:

conv0:stride=2, output=150x150, pad=(1, 1, 1, 1)
conv1:stride=1, output=150x150, pad=(1, 1, 1, 1)
conv2:stride=2, output=75x75, pad=(1, 1, 1, 1)
conv3:stride=1, output=75x75, pad=(1, 1, 1, 1)
conv4:stride=2, output=38x38, pad=(1, 1, 1, 1)
conv5:stride=1, output=38x38, pad=(1, 1, 1, 1)
conv6:stride=2, output=19x19, pad=(1, 1, 1, 1)
conv7:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv8:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv9:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv10:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv11:stride=1, output=19x19, pad=(1, 1, 1, 1)
conv12:stride=2, output=10x10, pad=(1, 1, 1, 1)
conv13:stride=1, output=10x10, pad=(1, 1, 1, 1)
leon-liangwu commented 7 years ago

@chuanqi305 Hi, how about your result when you use the converted caffemodel to test on ImageNet dataset.