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

Changes to made for more than 5 classes #9

Closed
PiyalGeorge opened this issue Oct 31, 2018 · 7 comments
Closed

Changes to made for more than 5 classes #9

PiyalGeorge opened this issue Oct 31, 2018 · 7 comments

Comments

@PiyalGeorge
Copy link

PiyalGeorge commented Oct 31, 2018

Thanks @Ghustwb for this repo. Finally it worked. I trained a model in with 5 classes and it worked. But how to make it work for 7 classes? I mean where all we have to make changes?

@Ghustwb
Copy link
Owner

Ghustwb commented Oct 31, 2018

1、pluginImplement.cpp reshape layer
2、pluginImplement.h softmax
3、pluginImplement.cpp detection_out layer
you could replace "5" with "7"

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Nov 14, 2018

@Ghustwb , extremely Sorry for the late reply. I tried changing following things, but still getting error:-
In pluginImplement.cpp
line number 369 - mMbox_conf_reshape = std::unique_ptr<Reshape<5>>(new Reshape<5>());
line number 392 - params.numClasses = 5;
line number 652 - mMbox_conf_reshape = std::unique_ptr<Reshape<5>>(new Reshape<5>(serialData, serialLength));
In pluginImplement.h
line number 150 - assert((inputs[0].d[0])*(inputs[0].d[1]) % 5 == 0);
line number 320 - std::unique_ptr<Reshape<5>> mMbox_conf_reshape{ nullptr };

then i clean, cmake, make. when i run the command './build/bin/mobileNet' , i get following error-

attempting to open cache file ../../model/MobileNetSSD_deploy.caffemodel.1.tensorcache
cache file not found, profiling network model
../../model/MobileNetSSD_deploy_iplugin.prototxt
../../model/MobileNetSSD_deploy.caffemodel
CaffeParser: Could not open file ../../model/MobileNetSSD_deploy.caffemodel
CaffeParser: Could not parse model file
mobileNet: /home/nvidia/MobileNet-SSD-TensorRT-master/tensorNet.cpp:105: bool TensorNet::caffeToTRTModel(const char*, const char*, const std::vector<std::__cxx11::basic_string<char> >&, unsigned int, std::ostream&): Assertion `blobNameToTensor != nullptr' failed.
Aborted

I also saw this line in pluginImplement.h line number 167, 168 -
//cudaSoftmax( 8732 *21, 21, (float *) *inputs, static_cast<float *>(*outputs));
cudaSoftmax( 1917 *5, 5, (float *) *inputs, static_cast<float *>(*outputs));

Do i need to make any change in above line 167, 168 in pluginImplement.h? what is 8732 and 1917? so i need to change that?
Is there something else i need to change? Please help

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Nov 15, 2018

@Ghustwb Please help

@Ghustwb
Copy link
Owner

Ghustwb commented Nov 16, 2018

Sorry for the late reply

//cudaSoftmax( 8732 *21, 21, (float *) *inputs, static_cast<float *>(*outputs));
cudaSoftmax( 1917 *5, 5, (float *) *inputs, static_cast<float *>(*outputs));

In SSD,the backbone is VGG16,Conv4_3 (38*38)can get 4 boxes of different widths and heights,Conv7 (19*19) get 6 boxes,Conv8_2 and Conv9_2 get 6 boxes,Conv 10_2 and Conv11_2 get 4 boxes. So,

38*38*4+19*19*6+10*10*6+5*5*6+3*3*4+4 = 8732。

In MobileNet-SSD,the backbone is mobileNet,so the number of boxes is different with SSD.
you can read the paper of mobileNet.

If you use 2 classes, you should chage it

cudaSoftmax( 1917 *2, 2, (float *) *inputs, static_cast<float *>(*outputs));

@PiyalGeorge
Copy link
Author

PiyalGeorge commented Nov 19, 2018

Thanks @Ghustwb , Finally figured out. Actually it was simple, but took a lot of time to figure it out.
For guys who are still looking for the same answer, give me a smiley here, 😃 , Just kidding.

For changing classes from 5 to our custom number of classes make changes in following files:

(custom number of classes mentioned here is including background)

In pluginImplement.cpp:
make change in following lines from 5 to your custom number of classes:
369
392
652

In pluginImplement.h:
make change in following lines from 5 to your custom number of classes:
150
168
320

In MobileNetSSD_deploy_iplugin.prototxt:
Change lines, where n is number of classes including background

650 - 15 to n * 3
701 - 30 to n * 6
752 - 30 to n * 6
803 - 30 to n * 6
854 - 30 to n * 6
905 - 30 to n * 6

example, below is for changing 5(including background) classes to 3(including background)

650 - 15 to 9
701 - 30 to 18
752 - 30 to 18
803 - 30 to 18
854 - 30 to 18
905 - 30 to 18

Thanks

@vagrant-drift
Copy link

@PiyalGeorge just make changes in these files? Need to retrain?

@PiyalGeorge
Copy link
Author

Hi @xiongdahua555 , the caffemodel(Mobilenet-ssd) in this repo by Ghustwb is having 5 classes. if you have a custom class trained with similar number of classes, just replace Ghustwb's model with that. and do make changes in above files. Also i got an error when tried the same with 21 classes model(Maybe more changes might be needed, but i didn't checked into that since i already got results with 3). When i tried with 3 classes the above changes gave successful results. Thank you

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

3 participants