Git Product home page Git Product logo

mobilenet-ssd's Introduction

MobileNet-SSD

A caffe implementation of MobileNet-SSD detection network, with pretrained weights on VOC0712 and mAP=0.727.

Network mAP Download Download
MobileNet-SSD 72.7 train deploy

Run

  1. Download SSD source code and compile (follow the SSD README).
  2. Download the pretrained deploy weights from the link above.
  3. Put all the files in SSD_HOME/examples/
  4. Run demo.py to show the detection result.
  5. You can run merge_bn.py to generate a no bn model, it will be much faster.

Create LMDB for your own dataset

  1. Place the Images directory and Labels directory into same directory. (Each image in Images folder should have a unique label file in Labels folder with same name)
  2. cd create_lmdb/code
  3. Modify the labelmap.prototxt file according to your classes.
  4. Modify the paths and directories in create_list.sh and create_data.sh as specified in same file in comments.
  5. run bash create_list.sh, which will create trainval.txt, test.txt and test_name_size.txt
  6. run bash create_data.sh, which will generate the LMDB in Dataset directory.
  7. Delete trainval.txt, test.txt, test_name_size.txt before creation of next LMDB.

Train your own dataset

  1. Convert your own dataset to lmdb database (follow the SSD README), and create symlinks to current directory.
ln -s PATH_TO_YOUR_TRAIN_LMDB trainval_lmdb
ln -s PATH_TO_YOUR_TEST_LMDB test_lmdb
  1. Create the labelmap.prototxt file and put it into current directory.
  2. Use gen_model.sh to generate your own training prototxt.
  3. Download the training weights from the link above, and run train.sh, after about 30000 iterations, the loss should be 1.5 - 2.5.
  4. Run test.sh to evaluate the result.
  5. Run merge_bn.py to generate your own no-bn caffemodel if necessary.
python merge_bn.py --model example/MobileNetSSD_deploy.prototxt --weights snapshot/mobilenet_iter_xxxxxx.caffemodel

About some details

There are 2 primary differences between this model and MobileNet-SSD on tensorflow:

  1. ReLU6 layer is replaced by ReLU.
  2. For the conv11_mbox_prior layer, the anchors are [(0.2, 1.0), (0.2, 2.0), (0.2, 0.5)] vs tensorflow's [(0.1, 1.0), (0.2, 2.0), (0.2, 0.5)].

Reproduce the result

I trained this model from a MobileNet classifier(caffemodel and prototxt) converted from tensorflow. I first trained the model on MS-COCO and then fine-tuned on VOC0712. Without MS-COCO pretraining, it can only get mAP=0.68.

Mobile Platform

You can run it on Android with my another project rscnn.

mobilenet-ssd's People

Contributors

chuanqi305 avatar kunalgoyal9 avatar lngao avatar patataman avatar piyalgeorge avatar qinhj avatar shashikant-ghangare avatar sivakumarvvdn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mobilenet-ssd's Issues

Failed to start an training using my own data

Hi I'm trying to train a model using my own data that have only one class. I created my labelmap.prototxt like that

item {
  name: "none_of_the_above"
  label: 0
  display_name: "background"
}
item {
  name: "hand"
  label: 1
  display_name: "hand"
}

then I run the script ./gen_model.sh 2
Start a training ./train.sh

screen shot 2017-10-28 at 3 44 32 pm

I'm not sure do i need a label for none_of_the_above = background and my class number should be 1 or 2

Thanks

coco trainning

@chuanqi305 thanks for your great job.

I saw you update the README about you had ever trained on coco. I am training coco, but after 50000 iteration, the loss is still 8.0. Is that right? How many iterations you train coco? Could you please check the coco 81 setup.

ps: I had add force_color: true in the MobileNetSSD_train.prototxt, or it will coredump.

I0802 10:37:42.755049  4918 solver.cpp:243] Iteration 55210, loss = 7.94175
I0802 10:37:42.755126  4918 solver.cpp:259]     Train net output #0: mbox_loss = 7.04632 (* 1 = 7.04632 loss)
I0802 10:37:42.788318  4918 sgd_solver.cpp:138] Iteration 55210, lr = 0.000125
I0802 10:38:08.430493  4918 solver.cpp:243] Iteration 55220, loss = 7.96467
I0802 10:38:08.430521  4918 solver.cpp:259]     Train net output #0: mbox_loss = 7.99792 (* 1 = 7.99792 loss)
I0802 10:38:08.608438  4918 sgd_solver.cpp:138] Iteration 55220, lr = 0.000125
I0802 10:38:35.221209  4918 solver.cpp:243] Iteration 55230, loss = 7.33587
I0802 10:38:35.221287  4918 solver.cpp:259]     Train net output #0: mbox_loss = 7.33598 (* 1 = 7.33598 loss)
I0802 10:38:35.338119  4918 sgd_solver.cpp:138] Iteration 55230, lr = 0.000125

about scale layer

Hi @chuanqi305,
May i know why do you use smaller lr_mult and decay_mult for scale layer? Is there some reasons?
Thanks,

train time

Hi, thanks for your works,I have a problem I use your file in the VOC0712 on the training, the training speed is particularly slow, more than 20 hours only iterative training more than 2000 times, what is the reason?

Please explain the training steps using own dataset

Hi All,
I am new to SSD. Could someone please explain the step by step process to train the SSD model using my own dataset in caffe. Also could you please let me know if MobileNetSSD_train.prototxt file used in this post are fine to use with caffe. When I am using the MobileNetSSD_train.prototxt file to generate .caffemodel I am getting Message type "caffe.TransformationParameter" has no field named "resize_param" error.
Thanks,
Debojit

Is the trained model compatible with Open dnn module ?

Hello Friends,
I want to train SSD mobile net caffe model with my custom dataset. After obtaining the caffemodel and deploy.prototxt will I be able to use them in Opencv dnn modules Code using caffe importer or it can be used only in original caffe program ? I am new to this deep learning and opencv field . Can anyone please clarify my doubt ? Thanks :)

some train problem

Thanks for your work, I use kitty dataset and your method to train a model.lr=0.0005,120000 iter,stepsize=20000,but i have the 48% auccury.can you give some advice?Thanks

pretrained model

Can you please share your petrained model ?My data set is too small to train from begining.Thanks a lot!

merge_bn.py使用与否问题

你好,多谢分享!我的问题如下:
1.我运行gen_model.sh生成了用以训练人脸(2类)检测的网络文件。使用的是wideface训练的,loss一直在震荡(2,3,4,5这样),fddb测试recall 最高为0.9。我不知道我的操作步骤是否有误。
2.另外我没有使用merge_bn.py,因为我发现我的deploy文件中已经有batch_norm和scale层了,确实是由gen_model.sh生成的。
3.另外我运行gen.py生成网络文件,输入图像大小为512x512,但我在运行训练的时候遇到num_output 63 目标6,不匹配的错误,不知该如何修改。

请问merge_bn中,weights的操作为何与bias不同?

感谢您的工作,有一点不太明白,请指教!
'''
merge the batchnorm, scale layer weights to the conv layer, to improve the performance
var = var + scaleFacotr
rstd = 1. / sqrt(var + eps)
w = w * rstd * scale
b = (b - mean) * rstd * scale + shift
'''
为何不是
w = (w - mean)* rstd * scale+ shift
b = (b - mean) * rstd * scale + shift

谢谢,祝好

there is some wrong with the train-net you provided

Hi,I used MobileNetSSD_train.prototxt you provided to train the model,but when i used MobileNetSSD_deploy.prototxt to test the model,there is
some wrong with MobileNetSSD_deploy.prototxt, "Incompatible error ",so i fixed the wrong and test the model,but could not find any detections,so can you tell me how to train the model?the MobileNetSSD_train.prototxt and MobileNetSSD_deploy.prototxt you provided is right?
thank you very much!

Couldn't find any detections

use examples/ssd/ssd_detect

and then get follow result

detection_output_layer.cpp:282] Couldn't find any detections

any difference?

Converting classification model from tensorflow to caffe

Hello!
I have been trying to train mobilenet-ssd on my own using the method described by you. However I have been facing a lot of issues while importing the weights learnt by tensorflow-mobilenet into a working caffemodel. Can you please let me know of the procedure that you followed while converting the classifier MobileNet checkpoint from tensorflow to a working caffemodel?
I have imported the weights into caffe and tried running the caffemodel but the activations turn to NaNs after a certain layer. I think there is a problem with importing batchnorm/scale layer weights but I haven't been able to pinpoint the problem yet.
Thank you!

About the different caffemodels of train, deploy and nofc

Hi chuanqi305,

Good jobs!

I have two questions about the three different caffemodels: MobileNetSSD_train.caffemodel(train), MobileNetSSD_deploy.caffemodel(deploy), MobileNet_nofc.caffemodel(nofc):

  1. The train weights is about 23M, but why the deploy's weights increase to 32M after merging bn?
  2. The nofc is surprised because it's weights only is about 8M! How did you get the caffemodel of nofc, and can you provide the train.prototxt for nofc?

Look forward to your further discussion!

Best.

The parameters problem(num of priorbox)

self.mbox("conv11", 3)

Hi, chuanqi305, why the parameter here is 3 ,not 4? Because according to weiliu89's source code in "prior_box_layer.cpp", if aspect ratio = [2.0], there should be 4 default boxes, their width are:

  1. aspect = 1.0 width = min_size
    2.aspect = 1.0 width = sqrt(min_size*max_size)
  2. aspect = 2.0 width = min_size * sqrt(2.0)
  3. aspect = 1/2.0 width = min_size * sqrt(1/2.0)

Thanks for your explanation here.

test result error

Hi i retrain the mobiliNet+SSD using voc0712 , after 25000 iters, mAp is 0.724 and loss decrease ~2.0
but when i using python demo.py after merge_bn.py ,the result is poor..like this:

nu8mtm1c ith5fimqcq_c

what's the wrong

about some details

hello, I am very interested in your job. I want to know, what dataset do you trained? how is the mAP?
and can you share the pre-trained models?
do you mind adding a qq num? my qq num is 905298777. thanks!

FPS consultation

hi,
i want to know the fps on the mobile phone just like android and ios, thanks!

processing time

thank you very much for your work.
i have trained my own data and deployed the model (300x300) with visual studio 2013 on one GPU gtx 1070.
but the detection time was 35ms per image, the same with VGG-16 model.
what could be the problem?

Test frame

Hi,thanks for your codes,I tested the results after training only 12~19 frams/s, this normal?

can not load the pretrained MobiletNet

Hi, I am trying to load the pretrained mobilenet and prototxt , but i have this following error :

Check failed: target_blobs.size() == source_layer.blobs_size() (5 vs. 3) Incompatible number of blobs for layer conv0/bn

Any idea of why this happen, the error is telling me that the input number of blobs for conv0/bn is 3 while the output is 5

Inconsistency between MobileNet-SSD and original SSD

Hi Chuanqi,

I noticed that there are several inconsistencies between your MobileNetSSD_deploy.prototxt and the original SSD network (Ref: https://github.com/weiliu89/caffe/blob/ssd/examples/ssd/score_ssd_coco.py).
I can see that the first 14 layers (0 -> 13) are identical with MobileNet(base net for SSD), but later since conv16_2, there're some difference.
In your network (following lines is in order: layer_name, out_channel, kernel size, padding, stride):
conv_16_2, oc=256, ks = 3, pad=1, s=2;
(original, oc=256, ks=3, pad=0, s=1)
conv_17_1, oc=64, ks=1, pad=0, s=1;
(original, oc=128, ks=1, pad=0, s=1)
conv_17_2, oc=128, ks=3, pad=1, s=2;
(original, oc=256, ks=3, pad=0, s=1)
Is there any particular reasons why you do so?
Or if there's something I didn't understand correctly, could you please help me here please?

Thank you

error in running demo.py

I downloaded your pretrained model and got the following error when running python demo.py.
SSD-caffe is compiled with CPU mode only since I don't have a graphic card. Any idea why this error happens.

/usr/local/lib/python2.7/dist-packages/google/protobuf/init.py:37: UserWarning: Module numpy was already imported from /usr/local/lib/python2.7/dist-packages/numpy/init.pyc, but /usr/lib/python2.7/dist-packages is being added to sys.path
import('pkg_resources').declare_namespace(name)
/usr/local/lib/python2.7/dist-packages/google/protobuf/init.py:37: UserWarning: Module six was already imported from /usr/local/lib/python2.7/dist-packages/six.pyc, but /usr/lib/python2.7/dist-packages is being added to sys.path
import('pkg_resources').declare_namespace(name)
WARNING: Logging before InitGoogleLogging() is written to STDERR
W0814 19:52:40.115876 17813 _caffe.cpp:139] DEPRECATION WARNING - deprecated use of Python interface
W0814 19:52:40.115895 17813 _caffe.cpp:140] Use this instead (with the named "weights" parameter):
W0814 19:52:40.115898 17813 _caffe.cpp:142] Net('MobileNetSSD_deploy.prototxt', 1, weights='MobileNetSSD_deploy.caffemodel')
[libprotobuf ERROR google/protobuf/text_format.cc:274] Error parsing text-format caffe.NetParameter: 1177:17: Message type "caffe.LayerParameter" has no field named "permute_param".
F0814 19:52:40.117127 17813 upgrade_proto.cpp:88] Check failed: ReadProtoFromTextFile(param_file, param) Failed to parse NetParameter file: MobileNetSSD_deploy.prototxt
*** Check failure stack trace: ***
Aborted (core dumped)

merge error

when I use merge_bn.py to output deploy.prototxt ,but it appeares the KeyError: 'convll_mbox_conf_new' 。can you tell what the error happened? thanks very much.

Ask some details of training

Thanks for your job. I'm trying to use your classification model to training the Mobilenet-SSD. The training is only on the VOC07/12 dataset(without pre-training on the COCO), but it seems so hard to get a high mAP as yours(0.68). Would you share some details about it, i.e solver parameter like (base_lr, lr_policy, max_iter) . Or there is some difference with your pre-trained model's deploy.prototxt, i.e. parameter like(lr_mult=0.1, decay_mult=0.1 for depthwise separable convolution). Or frozen some layer at initial stage? Thanks very much~~

Could you share the coco trained model for me?

Hi,
Thanks for your great work. The speed is much faster than the original SSD model.
I am finetuning the model to Pedestrain detection but havenot get good results from the voc 73000 iterations model. Could you share the coco pretrained model, if it is convenient? I think maybe the coco pretrained model has more generality. And finetuning on that will get better result than finetuning on voc model.
Thanks again for you great work.

Can't get correct output when running in NVIDIA TensorRT

Hi Chuanqi305,

I am Deep Learning Software Engineer in NVIDIA Shanghai.
Thanks for your nice job here, and I tried to run your model in NVIDIA TensorRT optimizer.
But unfortunately can't get correct ouptput, can I add your WeChat to discuss more ?
Thanks.

Best Regards
Nic Ma

传奇 大神,请教一个使用自己数据集训练模型的问题。关于labelmap.prototxt文件搜不到材料,你的文件中哪一个与之类似可以参考的呢?

传奇你好, 我最近有个项目要用OpenCVDNN做的,里面用到了caffemodel, 里面给的链接指向你的项目。现在我需要根据项目要求自己收集数据训练模型生成“.caffemodel”和“.prototxt”文件然后在OpenCV里面用。目前我已经下载了SSD的文件(Weiliu的caffe吧),编译通过,把你的文件也添加进去了,跑了你的demo。 现在我的目标是根据自己采集的图片生成“.caffemodel”和“.prototxt”。目前不知道这个labelmap是啥,也不太清楚具体过程,训练集的要求,大神可以指导一下吗?十分感谢

something confused about solver

Hi, thanks for sharing your great job. I just get something confused about solver. 'test_iter: 673', i check the original produces test.prototxt, the batchsize is 8, and there are 4952 images int the VOC07 test set, but according to your set: 8 * 673 = 5384... what does it mean?
Looking forward to your reply.
Best regards

The speed of cpu mode

hello, I have trained my own data ,and test on my Computer
Size 300*300 inference
(i7 -6700HQ CPU) use125ms(FPS = 8) , why the speed is too slow ?
Hope to get your answer

False detections

I wonder if my result from demo.py is correct. Are the detections in the attached images expected? There seem to be many false detections.
000001_detect
000067_detect
000456_detect
000542_detect
001150_detect
001763_detect
004545_detect

ssd_detect.bin couldn't find any objects

传奇你好,我按照你的步骤训练得到了自己的检测模型(MobileNetSSD_deploy.caffemodel和MobileNetSSD_deploy.prototxt),然后使用ssd_detect.bin进行测试,发现无法检测到任何目标,请问你知道怎么回事吗?

problems when using 'merge.py'

Hi, chuanqi305:
I've successfully trained my own dataset with your code, and my number of classes is 5.
When I tried to use your 'merge.py' to get the deploy model, I firstly got the error:

KeyValue Error : 'conv11_mbox_conf_new'.

So to solve this, need to rename 6 *_mbox_conf layers in deploy prototxt.

And know I got the new error: (I've already modify the num_output in both deploy and train prototxt)

`
I0807 11:20:04.707312 18966 net.cpp:434] mbox_priorbox <- conv11_mbox_priorbox

I0807 11:20:04.707326 18966 net.cpp:434] mbox_priorbox <- conv13_mbox_priorbox

I0807 11:20:04.707340 18966 net.cpp:434] mbox_priorbox <- conv14_2_mbox_priorbox

I0807 11:20:04.707352 18966 net.cpp:434] mbox_priorbox <- conv15_2_mbox_priorbox

I0807 11:20:04.707366 18966 net.cpp:434] mbox_priorbox <- conv16_2_mbox_priorbox

I0807 11:20:04.707379 18966 net.cpp:434] mbox_priorbox <- conv17_2_mbox_priorbox

I0807 11:20:04.707396 18966 net.cpp:408] mbox_priorbox -> mbox_priorbox

I0807 11:20:04.707414 18966 net.cpp:150] Setting up mbox_priorbox

I0807 11:20:04.707429 18966 net.cpp:157] Top shape: 1 2 7668 (15336)

I0807 11:20:04.707442 18966 net.cpp:165] Memory required for data: 87688080

I0807 11:20:04.707453 18966 layer_factory.hpp:77] Creating layer mbox_conf_reshape

I0807 11:20:04.707469 18966 net.cpp:100] Creating Layer mbox_conf_reshape

I0807 11:20:04.707481 18966 net.cpp:434] mbox_conf_reshape <- mbox_conf

I0807 11:20:04.707496 18966 net.cpp:408] mbox_conf_reshape -> mbox_conf_reshape

F0807 11:20:04.707522 18966 reshape_layer.cpp:80] Check failed: 0 == bottom[0]->count() %

explicit_count (0 vs. 9) bottom count (9585) must be divisible by the product of the specified dimensions (21)
`

I don't know where to modify now.
Waiting for you suggestion.
Thanks

How to set anchor box parameters?

Hi Chuanqi, appreciate your work!
I have a question, how can I set the number of defaut boxes?(For weiliu's SSD, its first priorbox layer has 4 defaut boxes instead of your 3.) It seems that if I want to change it, I need to rebuild the whole model.
Looking forward for your suggestions.

Test the mAP of pretrained model failed

After downloading the pretrained model, the mAP of model 'mobilenet_iter_73000.caffemodel' is only 0.007. It seems that some layers didn't load pretrained weights, and I found that some layers , such as 'conv11_mbox_conf', 'conv13_mbox_conf','conv14_2_mbox_conf' , are ignored during loading pretrained weights. From this view, it seems that the layers'names are incompatible between caffemodel and prototxt files. Is it some error or bug?

Training Log

Will it be possible for you to share your training log which gives 72.7 det accuracy on VOC0712?

I am trying to train using base network provided at https://github.com/shicai/MobileNet-Caffe. I am using Caffe-SSD, 300x300 script so it is little different from your script but wanted to compare if my training is progressing fine or not.

Thanks.
Soyeb

num of mbox_conf layers

Hi chuanqi305,
I tried to train my own dataset according to your instructions, and I found that there're 6 mbox_conf layers: conv11, conv13, conv14_2, conv15_2, conv16_2, conv17_2. It's a mistake or I misunderstand someting here?

One more question: why should I change the name of mbox_conf layers? If I change the names, we should also change the name for some "bottom" and "top" names, right?

Thanks.

How to get MobileNetSSD_deploy.caffemodel

Hi All,
We are using merge_bn.py to merge mobilenet_iter_73000.caffemodel and MobileNetSSD_deploy.caffemodel. I believe we are generatingmobilenet_iter_73000.caffemodel file running thetrain.sh. Could any body explain how are we getting the MobileNetSSD_deploy.caffemodel file.
Thanks,
Debojit

details about finetune

Thanks for your code.
COCO dataset has about 80+ classes while VOC dataset has about 21 class. When finetune model on VOC dataset from weights trained on COCO dataset, are we just use the common layers while the specific layers are trained from scratch?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.