Train Multiple classes in DetectNet
To train a DetectNet that can recognize multiple classes, you need to modify a few lines of the DetectNet.prototxt. There are total 7 places of the code you need to modify.
- train_transform layer and val_transform
In the train_transform layer and val_transform layer(around line 76 and 116)
add object_class fields that match your number of classesFor example, if you have 3 classes, you need to add
object_class: { src: 1 dst: 0} object_class: { src: 2 dst: 1} object_class: { src: 3 dst: 2}
- Number of output in convolution parameter
Change the num_output equal to your number of classes(around line 2379)
For example, if you have 3 classes, you need to change
num_output: 3
- Cluster bboxes’ layer
add more top layer parameter (around line 2499)
For example, if you have 3 classes, you need to add
top: 'bbox-list-class0' top: 'bbox-list-class1' top: 'bbox-list-class2'
- param_str value in Cluster bboxes’ layer
change the last parameter of the param_str
param_str : ‘1920, 1152, 16, 0.05, 1, 0.02, 22, NUM_OF_CLASSES’
param_str : '1920, 1152, 16, 0.05, 1, 0.02, 22, 3'
- Calculate mean average precision’s layer
add more top layer parameter (around line 2514), just same as the Cluster bboxes’ layer mentioned in step 3.
For example, if you have 3 classes, you need to add
top: 'bbox-list-class0' top: 'bbox-list-class1' top: 'bbox-list-class3'
- param_str value in Calculate mean average precision’s layer
change the last parameter of the param_str
param_str : ‘1920, 1152, 16, NUM_OF_CLASSES’
param_str : '1920, 1152, 16, 3'
- Final Output Layer
Insert the number of output layer that match your number of classes. If you have 3 classes, you need to insert 3 set of the
layers.The name inside bottom layer parameter must be same as above
An example of 1 set of a layer. #class 0 layer { type: 'Python' name: 'score-class0' bottom: 'bbox-list-label-class0' bottom: 'bbox-list-class0' top: 'bbox-list-scored-class0' python_param { module: 'caffe.layers.detectnet.mean_ap' layer: 'ScoreDetections' } include: { phase: TEST stage: "val" } } layer { type: 'Python' name: 'mAP-class0' bottom: 'bbox-list-scored-class0' top: 'mAP-class0' top: 'precision-class0' top: 'recall-class0' python_param { module: 'caffe.layers.detectnet.mean_ap' layer: 'mAP' param_str : '1920, 1152, 16' } include: { phase: TEST stage: "val" } }
2017-07-31 at 5:11 pm
Hi, can I have your email for ask the question?
thank!
Aaron
LikeLike
2017-08-22 at 12:53 pm
In your example NUM_OF_CLASSES =3, however in step 6 it is 2. Is this a typo, or is it N-1?
LikeLike
2017-08-22 at 3:10 pm
yes, it was a typo. It should be 3 in there.
param_str : ‘1920, 1152, 16, 3’
LikeLike
2018-01-15 at 4:14 pm
Hi – Thank you for your tutorial. I got this error when I tried to run the code.
ERROR: Layer ‘cluster’ references bottom ‘bbox-list-label-class0’ at the TEST stage however this blob is not included at that stage. Please consider using an include directive to limit the scope of this layer.
Can you please give me some guidance to fix it?
LikeLike
2018-01-15 at 4:20 pm
The error may be due to bottom layer. Do I add bottom layer in step 3 and 5? Like add bbox-list-label-class0 in step 3 and 5.
LikeLike
2018-03-05 at 11:15 am
I think yes, you can try this.
LikeLike
2018-02-15 at 6:05 pm
CaffeTrainSanityCheckError: Layer ‘score-class0’ references bottom ‘bbox-list-label-class0’ at the TEST stage however this blob is not included at that stage. Please consider using an include directive to limit the scope of this layer.
LikeLike
2018-06-26 at 1:45 pm
How to label objects in images? As I knew, detectNet using KITTI format, so, How to do if I want to train with my labels, ex: Pepsi, Coca, …?
LikeLike
2018-06-28 at 10:33 pm
I am using this open source project to label the object in the images.
https://github.com/prabindh/euclid
LikeLiked by 1 person
2018-08-02 at 1:52 pm
Thank you so much for your answer,
Can you help me in this problem: https://devtalk.nvidia.com/default/topic/1038085/gpu-accelerated-libraries/cannot-train-detectnet-for-multiclass-/
LikeLike
2018-08-03 at 11:04 pm
How did you config your network? Did you load the dataset correctly?
LikeLike
2019-08-30 at 4:03 pm
does this change method make sense for the segmentation model?
LikeLike
2020-02-17 at 4:42 pm
I haven’t test it. You may try it to see the performance.
LikeLike