Skip to content

Commit f16c7ee

Browse files
committed
Fixes for OpenCV face detection network
1 parent 6f35400 commit f16c7ee

8 files changed

Lines changed: 26 additions & 12 deletions

File tree

modules/dnn/misc/face_detector_accuracy.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,13 @@ def detect(img, imageId):
154154
top = int(out[0, 0, i, 4] * img.shape[0])
155155
right = int(out[0, 0, i, 5] * img.shape[1])
156156
bottom = int(out[0, 0, i, 6] * img.shape[0])
157-
addDetection(detections, imageId, left, top, width=right - left + 1,
158-
height=bottom - top + 1, score=confidence)
157+
158+
x = max(0, min(left, img.shape[1] - 1))
159+
y = max(0, min(top, img.shape[0] - 1))
160+
w = max(0, min(right - x + 1, img.shape[1] - x))
161+
h = max(0, min(bottom - y + 1, img.shape[0] - y))
162+
163+
addDetection(detections, imageId, x, y, w, h, score=confidence)
159164

160165
elif args.cascade:
161166
cascade = cv.CascadeClassifier(args.cascade)

modules/dnn/misc/quantize_face_detector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ def l2norm(x, name):
173173
conv7_2_h = conv(conv7_2_h, stride=2, pad='VALID', name='conv7_2_h', activ=tf.nn.relu)
174174

175175
conv8_1_h = conv(conv7_2_h, pad='SAME', name='conv8_1_h', activ=tf.nn.relu)
176-
conv8_2_h = conv(conv8_1_h, pad='SAME', name='conv8_2_h', activ=tf.nn.relu)
176+
conv8_2_h = conv(conv8_1_h, pad='VALID', name='conv8_2_h', activ=tf.nn.relu)
177177
conv9_1_h = conv(conv8_2_h, 'conv9_1_h', activ=tf.nn.relu)
178-
conv9_2_h = conv(conv9_1_h, pad='SAME', name='conv9_2_h', activ=tf.nn.relu)
178+
conv9_2_h = conv(conv9_1_h, pad='VALID', name='conv9_2_h', activ=tf.nn.relu)
179179

180180
conv4_3_norm = l2norm(layer_256_1_relu1, 'conv4_3_norm')
181181

modules/dnn/src/layers/detection_output_layer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class DetectionOutputLayerImpl CV_FINAL : public DetectionOutputLayer
198198
virtual bool supportBackend(int backendId) CV_OVERRIDE
199199
{
200200
return backendId == DNN_BACKEND_OPENCV ||
201-
(backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized && !_clip);
201+
(backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized);
202202
}
203203

204204
bool getMemoryShapes(const std::vector<MatShape> &inputs,
@@ -936,6 +936,7 @@ class DetectionOutputLayerImpl CV_FINAL : public DetectionOutputLayer
936936

937937
InferenceEngine::Builder::Layer l = ieLayer;
938938
l.getParameters()["eta"] = std::string("1.0");
939+
l.getParameters()["clip"] = _clip;
939940

940941
return Ptr<BackendNode>(new InfEngineBackendNode(l));
941942
}

samples/dnn/face_detector/deploy.prototxt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ layer {
17841784
}
17851785
code_type: CENTER_SIZE
17861786
keep_top_k: 200
1787-
confidence_threshold: 0.2
1787+
confidence_threshold: 0.01
17881788
clip: 1
17891789
}
17901790
}

samples/dnn/face_detector/deploy_lowres.prototxt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,5 +1786,6 @@ layer {
17861786
code_type: CENTER_SIZE
17871787
keep_top_k: 200
17881788
confidence_threshold: 0.01
1789+
clip: 1
17891790
}
17901791
}

samples/dnn/face_detector/opencv_face_detector.pbtxt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ node {
12211221
attr {
12221222
key: "padding"
12231223
value {
1224-
s: "SAME"
1224+
s: "VALID"
12251225
}
12261226
}
12271227
attr {
@@ -1311,7 +1311,7 @@ node {
13111311
attr {
13121312
key: "padding"
13131313
value {
1314-
s: "SAME"
1314+
s: "VALID"
13151315
}
13161316
}
13171317
attr {
@@ -2337,6 +2337,12 @@ node {
23372337
i: 400
23382338
}
23392339
}
2340+
attr {
2341+
key: "clip"
2342+
value {
2343+
b: true
2344+
}
2345+
}
23402346
}
23412347
node {
23422348
name: "reshape_before_softmax"

samples/dnn/face_detector/test.prototxt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ layer {
917917
}
918918
convolution_param {
919919
num_output: 128
920-
pad: 1
920+
pad: 0
921921
kernel_size: 3
922922
stride: 1
923923
weight_filler {
@@ -983,7 +983,7 @@ layer {
983983
}
984984
convolution_param {
985985
num_output: 128
986-
pad: 1
986+
pad: 0
987987
kernel_size: 3
988988
stride: 1
989989
weight_filler {
@@ -1810,6 +1810,7 @@ layer {
18101810
code_type: CENTER_SIZE
18111811
keep_top_k: 200
18121812
confidence_threshold: 0.01
1813+
clip: 1
18131814
}
18141815
}
18151816
layer {

samples/dnn/face_detector/train.prototxt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ layer {
10861086
}
10871087
convolution_param {
10881088
num_output: 128
1089-
pad: 1
1089+
pad: 0
10901090
kernel_size: 3
10911091
stride: 1
10921092
weight_filler {
@@ -1600,7 +1600,7 @@ layer {
16001600
}
16011601
convolution_param {
16021602
num_output: 16
1603-
pad: 1
1603+
pad: 0
16041604
kernel_size: 3
16051605
stride: 1
16061606
weight_filler {

0 commit comments

Comments
 (0)