MobileNetv2-SSDLite icon indicating copy to clipboard operation
MobileNetv2-SSDLite copied to clipboard

Issue converting retrained ssd_mobilenet_v2 to caffe model

Open maxritter opened this issue 6 years ago • 5 comments

I am able to convert the official ssd_mobilenet_v2 trained on MS COCO to a caffe model, by using dump_tensorflow_weight and load_caffe_weights afterwards.

However, when I want to convert my fine-tuned model based on this checkpoint, which only contains one class (apart from background), I fail at the load_caffe_weights conversion step.

I am not exactly sure what I have to change in order to reflect the variation in output classes. So first I changed the number of classes in dump_tensorflow_weights from 91 to 2 in line 56 and 97. I also created a new prototxt file by using: "python gen_model.py -s deploy -c 2 >deploy.prototxt"

When I execute load_caffe_weights, I get the following error: "IOError: [Errno 2] No such file or directory: 'output/Conv_bn_moving_mean.dat'" The "Conv_bn" output file has indeed no "moving_mean" variation, only "beta" and "gamma".

Am I missing some changes to load_caffe_weights? Thanks in advance for any help on this, I am really stuck here and this is an important project for me..

PS: I uploaded my model here: https://transfer.sh/6qrxJ/platedetection.pb. Its only class apart from background is "plate".

maxritter avatar Jun 26 '18 22:06 maxritter

@maxritter Did you find any solutions. I didn't changed 91 to 2 in dump_tensorflow_weights.py file. After changing that I get the error "cannot reshape array of size 157248 into shape (136,newaxis)". With number 91 I can see .dat files generated inside the outputs folder. But fails in load_caffe_weights.py with the error "ValueError: cannot reshape array of size 157248 into shape (6,576,1,1)"

chinthysl avatar Jul 12 '18 12:07 chinthysl

Unfortunately not. I think you need to rewrite a big part of the load_caffe_weights script, as the network structure / the components do change during training and export / freezing. So I ended up setting a caffe-ssd training pipeline on AWS EC2 and retraining my model there from scratch.

maxritter avatar Jul 12 '18 19:07 maxritter

@maxritter so you didn't try this MobilenetV2, but the MobileNetV1 by chuanqi305, did you?

chinthysl avatar Jul 13 '18 03:07 chinthysl

Exactly. I also infered the MobileNetV2 on my Movidius stick, but found no improvement in terms of speed compared to the V1. So I ended up retraining the MobileNetV1.

maxritter avatar Jul 19 '18 06:07 maxritter

My dataset contains one class too, after using dump_tensorflow_weight and load_caffe_weights .I tried to convert the deploy.caffemodel on my own dateset by using coco2voc.py and changed the num of classes in line47: neww = np.ones((x, 2, wt.shape[2])).besides, i changed the number of parameters in line12,maps=[0, x].After this,i generated deploy_voc.caffemodel and can run with it ,but another question is the loss value didn't drop.

tencyrush avatar Jul 30 '18 03:07 tencyrush