Adding new class to DNN face detector

Hello,

I successfully trained OpenCV Face detector using Caffe+SSD and our custom dataset as included in this description: opencv/how_to_train_face_detector.txt at master · opencv/opencv · GitHub

The detection works correctly and result are very good. Now I would like to add new detection class into the model. Let’s say “face_with_glasses”.

I added new class into labelmap.prototxt, increased num_classes in prototxt files and added new training samples with annotations. The training process immediately ended with the following error:

Check failed: num_priors_ * num_classes_ == bottom[1]->channels() Number of priors must match number of confidence predictions.

So I modified the prototxt files according to this Parameters to change for training custom data · Issue #7 · chuanqi305/SqueezeNet-SSD · GitHub and now the training process runs as usual and there seems to be no problem.

But the problem appears during the detection in OpenCV (version 4). The detection result is completely scrambled. It returns many totally wrong rectangles (where many of them are out of image bounds) with confidence 1.0.

What could be the cause of this problem?
Thank you.
Tomas

1 Like

I found out that I also need to change reshape_param>shape>dim in “mbox_conf_reshape” layer to correspond to the number of classes. Now the main problem is fixed and objects are correctly detected.

But the accuracy is lower than before. Should solver parameters be changed when adding the new class? Should I increase max_iter, step_value or something?

OpenCV actually uses ResNet-10 network. How was this network created? Is there some script that can regenerate the prototxt files for different parameters (num_classes, resolution, etc.)?

Not related to your problem, but I am also trying to train Caffe+SSD model using that guide. While training I am getting this error:

I0427 08:47:07.764628    26 net.cpp:283] Network initialization done.
[libprotobuf ERROR google/protobuf/text_format.cc:307] Error parsing text-format caffe.NetParameter: 1813:9: Message type "caffe.DetectionOutputParameter" has no field named "clip".

Can you help me fix this if you had similar issue? Thanks