# Adding new class to DNN face detector

**URL:** <https://forum.opencv.org/t/adding-new-class-to-dnn-face-detector/1309>\
**Category:** Uncategorized\
**Tags:** dnn\
**Created:** [February 3, 2021, 3:23pm UTC](https://forum.opencv.org/t/adding-new-class-to-dnn-face-detector/1309 "2021-02-03T15:23:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_K](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/tomas_k/32/875_2.png) [@Tomas\_K](https://forum.opencv.org/u/Tomas_K)\
**Post date:** [February 3, 2021, 3:23pm UTC](https://forum.opencv.org/t/adding-new-class-to-dnn-face-detector/1309/1 "2021-02-03T15:23:25Z")

</div>

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](https://github.com/opencv/opencv/blob/master/samples/dnn/face_detector/how_to_train_face_detector.txt)

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](https://github.com/chuanqi305/SqueezeNet-SSD/issues/7) 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

---

<div class="post-metadata">

**Author:** ![Tomas\_K](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/tomas_k/32/875_2.png) [@Tomas\_K](https://forum.opencv.org/u/Tomas_K)\
**Post date:** [February 7, 2021, 1:34pm UTC](https://forum.opencv.org/t/adding-new-class-to-dnn-face-detector/1309/2 "2021-02-07T13:34:32Z")

</div>

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.)?

---

<div class="post-metadata">

**Author:** ![astanwar99](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/astanwar99/32/1936_2.png) [@astanwar99](https://forum.opencv.org/u/astanwar99)\
**Post date:** [April 27, 2021, 4:27am UTC](https://forum.opencv.org/t/adding-new-class-to-dnn-face-detector/1309/3 "2021-04-27T04:27:19Z")

</div>

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
