chuanqi305 / MobileNetv2-SSDLite

Caffe implementation of SSD and SSDLite detection on MobileNetv2, converted from tensorflow.
MIT License
448 stars 231 forks source link

Issue converting retrained ssd_mobilenet_v2 to caffe model #22

Open maxritter opened 6 years ago

maxritter commented 6 years ago

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".

chinthysl commented 6 years ago

@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)"

maxritter commented 6 years ago

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.

chinthysl commented 6 years ago

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

maxritter commented 6 years ago

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.

tencyrush commented 6 years ago

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.