Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to train MobileNet-YOLO-v3-lite with custom dataset? #47

Closed
PiyalGeorge opened this issue Dec 26, 2018 · 11 comments
Closed

How to train MobileNet-YOLO-v3-lite with custom dataset? #47

PiyalGeorge opened this issue Dec 26, 2018 · 11 comments

Comments

@PiyalGeorge
Copy link

PiyalGeorge commented Dec 26, 2018

Hi, @eric612 , Thanks for this amazing repo. Your mobilenet-yolov3-lite model is giving good results with good fps.
Currently following your repo, i'm trying to do training on mobilenet-yolov3-lite with my custom dataset. I'm having 6 classes(including background), 50000 images converted to LMDB. I'm using train_yolov3_lite.sh for training. I modified mobilenet_yolov3_lite_train.prototxt, label_prototxt, LMDB and batch_size in here. My system allows a batch size of only 2 for training and 1 for testing(total 3). I have trained till 50000 iterations. I modified the classes in yolo_detect.cpp , make file, etc. then modified the demo_yolo_lite.sh for the new model. but it caused some convolution 'bias_term' issue in mobilenet_yolov3_lite_deploy.prototxt . Hence modified that deploy file also. After rectifying all these, when i try to run the model, it still doesn't give output, no errors. Can you help me resolve this?

@eric612
Copy link
Owner

eric612 commented Dec 26, 2018

mobilenet_yolov3_lite_deploy.prototxt was made from merge_bn.py , you can't use it directly.

I suggest you can try modify test.prototxt to deploy.prototxt first (replace data layer and remove eval. layer)

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Dec 28, 2018

Thanks @eric612 , I'll try that.
Also while training, do i need to change 'num_class', or 'num' anywhere in mobilenet_yolov3_lite_train.prototxt or in test.prototxt based on number of classes i'm training? (Cuz usually we do it right?)

In the last lines -

yolov3_param {
side: 26
num_class: 20
num: 3
......
}

@eric612
Copy link
Owner

eric612 commented Dec 28, 2018

See issue #12

@eric612 eric612 closed this as completed Jan 3, 2019
@globalmaster
Copy link

Hi, @eric612 , Thanks for this amazing repo. Your mobilenet-yolov3-lite model is giving good results with good fps.
Currently following your repo, i'm trying to do training on mobilenet-yolov3-lite with my custom dataset. I'm having 6 classes(including background), 50000 images converted to LMDB. I'm using train_yolov3_lite.sh for training. I modified mobilenet_yolov3_lite_train.prototxt, label_prototxt, LMDB and batch_size in here. My system allows a batch size of only 2 for training and 1 for testing(total 3). I have trained till 50000 iterations. I modified the classes in yolo_detect.cpp , make file, etc. then modified the demo_yolo_lite.sh for the new model. but it caused some convolution 'bias_term' issue in mobilenet_yolov3_lite_deploy.prototxt . Hence modified that deploy file also. After rectifying all these, when i try to run the model, it still doesn't give output, no errors. Can you help me resolve this?

Hi,

Have you solved this problem? Now I'm training on my own dataset and I'm facing the same problem with you. Can you help me resolve this?

Thanks

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Jan 7, 2019

Hi @eric612 , Extremely sorry for late reply. Thanks alot, your above mentioned methods worked perfectly for custom training and detection. Thanks 😊 😃

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Jan 7, 2019

Hi @globalmaster , Sorry for the late reply.
Actually all your answers is mentioned by @eric612 , in the above comments. Anyway i'll join all comments and here is what you want:
Hope you have LMDB database of custom dataset with specific classes. I'll explain how i've done with 5 classes(excluding background). For example i have 5 classes(person, dog, cat, car, bus).

In mobilenet_yolov3_lite_train.prototxt, modify:

  • lmdb file path
  • label_map.prototxt
  • Modify 'num_output: 75' in the file as follows:-
    the above 75 was obtained from the calculation (5+classno)*3, where classno is the number of classes(without considering background in the count), and here eric's classno is 20.
    So if you have 5 classes(for eg:- person, dog, cat, car, bus), then the value is (5+5)*3=30, so modify 'num_output: 75' in file to 'num_output: 30'.
  • Search for 'num_class: 20' in the file and modify the value as follows:-
    if you have 5 classes(for eg:- person, dog, cat, car, bus), then modify the value into 'num_class: 5'

In mobilenet_yolov3_lite_test.prototxt, modify:

  • lmdb file path
  • label_map.prototxt
  • Modify 'num_output: 75' in the file as follows:-
    the above 75 was obtained from the calculation (5+classno)*3, where classno is the number of classes(without considering background in the count), and here eric's classno is 20.
    So if you have 5 classes(for eg:- person, dog, cat, car, bus), then the value is (5+5)*3=30, so modify 'num_output: 75' in file to 'num_output: 30'.
  • Modify 'num_classes: 20' to 'num_classes: 5'
  • Modify 'num_classes: 21' to 'num_classes: 6'

Once Training is done:
Modify the MobileNet-YOLO/examples/yolo/yolo_detect.cpp. You need to modify line:
char* CLASSES[21] = { "background", ....., "train", "tvmonitor" };
with classes.

Then once again run make commands:

cd build
cmake ..
make -j4
make pycaffe

Now modify MobileNet-YOLO/demo_yolo_lite.sh . Just now the eric has uploaded new mobilenet_yolov3_lite_deploy.prototxt , https://github.com/eric612/MobileNet-YOLO/blob/master/models/yolov3/mobilenet_yolov3_lite_bn_deploy.prototxt .

In mobilenet_yolov3_lite_bn_deploy.prototxt, modify:-

  • Modify 'num_output: 75' in file to 'num_output: 30' following above same criterias
  • Modify 'num_classes: 20' to 'num_classes: 5'

Now go ahead and run the command bash demo_yolo_lite.sh
Thank you, Hope this helps you

@TianSong1991
Copy link

Hi @globalmaster , Sorry for the late reply.
Actually all your answers is mentioned by @eric612 , in the above comments. Anyway i'll join all comments and here is what you want:
Hope you have LMDB database of custom dataset with specific classes. I'll explain how i've done with 5 classes(excluding background). For example i have 5 classes(person, dog, cat, car, bus).

In mobilenet_yolov3_lite_train.prototxt, modify:

  • lmdb file path
  • label_map.prototxt
  • Modify 'num_output: 75' in the file as follows:-
    the above 75 was obtained from the calculation (5+classno)*3, where classno is the number of classes(without considering background in the count), and here eric's classno is 20.
    So if you have 5 classes(for eg:- person, dog, cat, car, bus), then the value is (5+5)*3=30, so modify 'num_output: 75' in file to 'num_output: 30'.
  • Search for 'num_class: 20' in the file and modify the value as follows:-
    if you have 5 classes(for eg:- person, dog, cat, car, bus), then modify the value into 'num_class: 5'

In mobilenet_yolov3_lite_test.prototxt, modify:

  • lmdb file path
  • label_map.prototxt
  • Modify 'num_output: 75' in the file as follows:-
    the above 75 was obtained from the calculation (5+classno)*3, where classno is the number of classes(without considering background in the count), and here eric's classno is 20.
    So if you have 5 classes(for eg:- person, dog, cat, car, bus), then the value is (5+5)*3=30, so modify 'num_output: 75' in file to 'num_output: 30'.
  • Modify 'num_classes: 20' to 'num_classes: 5'
  • Modify 'num_classes: 21' to 'num_classes: 6'

Once Training is done:
Modify the MobileNet-YOLO/examples/yolo/yolo_detect.cpp. You need to modify line:
char* CLASSES[21] = { "background", ....., "train", "tvmonitor" };
with classes.

Then once again run make commands:

cd build
cmake ..
make -j4
make pycaffe

Now modify MobileNet-YOLO/demo_yolo_lite.sh . Just now the eric has uploaded new mobilenet_yolov3_lite_deploy.prototxt , https://github.com/eric612/MobileNet-YOLO/blob/master/models/yolov3/mobilenet_yolov3_lite_bn_deploy.prototxt .

In mobilenet_yolov3_lite_bn_deploy.prototxt, modify:-

  • Modify 'num_output: 75' in file to 'num_output: 30' following above same criterias
  • Modify 'num_classes: 20' to 'num_classes: 5'

Now go ahead and run the command bash demo_yolo_lite.sh
Thank you, Hope this helps you

@PiyalGeorge
Hi PiyalGeorge, I follow your steps and run sh train_yolov3_lite_self.sh and finally I obtain the caffe model.But when I run python merge_bn.py --model example/mobilenet_yolov3_lite_solver.prototxt --weights snapshot/mydata_deploy_iter_20000.caffemodel
It makes run and the feedback as follow:

Traceback (most recent call last):
File "merge_bn.py", line 60, in
net_deploy = caffe.Net(deploy_proto, caffe.TEST)
RuntimeError: Could not open file /media/pico/data2/kevin/MobileNet-YOLO/data/VOCself/remove_bn.prototxt

Should I create the remove_bn.prototxt first?

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Jan 7, 2019

Hi @TianSong1991 , haven't you checked eric's latest update? he updated the repo today. There is no need for you to run merge_bn.py, since he has already gave you the file directly. This is the new file eric has added - https://github.com/eric612/MobileNet-YOLO/blob/master/models/yolov3/mobilenet_yolov3_lite_bn_deploy.prototxt .

In mobilenet_yolov3_lite_bn_deploy.prototxt, you need to modify as i specified above.
You also need to modify command in demo_yolo_lite.sh, with mobilenet_yolov3_lite_bn_deploy.prototxt

@TianSong1991
Copy link

Oh thank you very much! @PiyalGeorge

@shuxiao9058
Copy link
Contributor

  • the above 75 was obtained from the calculation (5+classno)*3, where classno is the number of classes(without considering background in the count), and here eric's classno is 20.

@PiyalGeorge
all the 75 in the train file need modify?

@PiyalGeorge
Copy link
Author

  • the above 75 was obtained from the calculation (5+classno)*3, where classno is the number of classes(without considering background in the count), and here eric's classno is 20.

@PiyalGeorge
all the 75 in the train file need modify?

Bro, Yes. Above it specifies to Modify 'num_output: 75' in the file. so search for 'num_output: 75' in the file and modify that only. 😃 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants