From 97681d0607e9fe25b05cd0ae7a3ce7dfeb13c55b Mon Sep 17 00:00:00 2001 From: LaurentBerger Date: Sun, 30 Jun 2019 18:39:05 +0200 Subject: [PATCH 1/2] Add clip to deploy.prototxt --- samples/dnn/face_detector/deploy.prototxt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/dnn/face_detector/deploy.prototxt b/samples/dnn/face_detector/deploy.prototxt index 905580ee46..75d33f00b0 100644 --- a/samples/dnn/face_detector/deploy.prototxt +++ b/samples/dnn/face_detector/deploy.prototxt @@ -1784,6 +1784,7 @@ layer { } code_type: CENTER_SIZE keep_top_k: 200 - confidence_threshold: 0.01 + confidence_threshold: 0.2 + clip: 1 } } From 47c5ee5d9c3ec0b2fca236b6003eef34aaa9ba56 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 27 Jul 2019 15:03:58 +0300 Subject: [PATCH 2/2] Fixes for OpenCV face detection network --- modules/dnn/misc/face_detector_accuracy.py | 9 +++++++-- modules/dnn/misc/quantize_face_detector.py | 4 ++-- modules/dnn/src/layers/detection_output_layer.cpp | 3 ++- samples/dnn/face_detector/deploy.prototxt | 2 +- samples/dnn/face_detector/opencv_face_detector.pbtxt | 10 ++++++++-- samples/dnn/face_detector/test.prototxt | 5 +++-- samples/dnn/face_detector/train.prototxt | 4 ++-- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/modules/dnn/misc/face_detector_accuracy.py b/modules/dnn/misc/face_detector_accuracy.py index 2f0350e00d..7d10264041 100644 --- a/modules/dnn/misc/face_detector_accuracy.py +++ b/modules/dnn/misc/face_detector_accuracy.py @@ -154,8 +154,13 @@ if args.proto and args.model: top = int(out[0, 0, i, 4] * img.shape[0]) right = int(out[0, 0, i, 5] * img.shape[1]) bottom = int(out[0, 0, i, 6] * img.shape[0]) - addDetection(detections, imageId, left, top, width=right - left + 1, - height=bottom - top + 1, score=confidence) + + x = max(0, min(left, img.shape[1] - 1)) + y = max(0, min(top, img.shape[0] - 1)) + w = max(0, min(right - x + 1, img.shape[1] - x)) + h = max(0, min(bottom - y + 1, img.shape[0] - y)) + + addDetection(detections, imageId, x, y, w, h, score=confidence) elif args.cascade: cascade = cv.CascadeClassifier(args.cascade) diff --git a/modules/dnn/misc/quantize_face_detector.py b/modules/dnn/misc/quantize_face_detector.py index 6dae0266ee..92e307ea3f 100644 --- a/modules/dnn/misc/quantize_face_detector.py +++ b/modules/dnn/misc/quantize_face_detector.py @@ -173,9 +173,9 @@ conv7_2_h = tf.space_to_batch_nd(conv7_1_h, [1, 1], [[1, 1], [1, 1]], name='Pad_ conv7_2_h = conv(conv7_2_h, stride=2, pad='VALID', name='conv7_2_h', activ=tf.nn.relu) conv8_1_h = conv(conv7_2_h, pad='SAME', name='conv8_1_h', activ=tf.nn.relu) -conv8_2_h = conv(conv8_1_h, pad='SAME', name='conv8_2_h', activ=tf.nn.relu) +conv8_2_h = conv(conv8_1_h, pad='VALID', name='conv8_2_h', activ=tf.nn.relu) conv9_1_h = conv(conv8_2_h, 'conv9_1_h', activ=tf.nn.relu) -conv9_2_h = conv(conv9_1_h, pad='SAME', name='conv9_2_h', activ=tf.nn.relu) +conv9_2_h = conv(conv9_1_h, pad='VALID', name='conv9_2_h', activ=tf.nn.relu) conv4_3_norm = l2norm(layer_256_1_relu1, 'conv4_3_norm') diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index fd2bf49794..3515a2b6bb 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -198,7 +198,7 @@ public: virtual bool supportBackend(int backendId) CV_OVERRIDE { return backendId == DNN_BACKEND_OPENCV || - (backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized && !_clip); + (backendId == DNN_BACKEND_INFERENCE_ENGINE && !_locPredTransposed && _bboxesNormalized); } bool getMemoryShapes(const std::vector &inputs, @@ -936,6 +936,7 @@ public: InferenceEngine::Builder::Layer l = ieLayer; l.getParameters()["eta"] = std::string("1.0"); + l.getParameters()["clip"] = _clip; return Ptr(new InfEngineBackendNode(l)); } diff --git a/samples/dnn/face_detector/deploy.prototxt b/samples/dnn/face_detector/deploy.prototxt index 75d33f00b0..72e50af434 100644 --- a/samples/dnn/face_detector/deploy.prototxt +++ b/samples/dnn/face_detector/deploy.prototxt @@ -1784,7 +1784,7 @@ layer { } code_type: CENTER_SIZE keep_top_k: 200 - confidence_threshold: 0.2 + confidence_threshold: 0.01 clip: 1 } } diff --git a/samples/dnn/face_detector/opencv_face_detector.pbtxt b/samples/dnn/face_detector/opencv_face_detector.pbtxt index 5f498aad50..60daa5e6be 100644 --- a/samples/dnn/face_detector/opencv_face_detector.pbtxt +++ b/samples/dnn/face_detector/opencv_face_detector.pbtxt @@ -1221,7 +1221,7 @@ node { attr { key: "padding" value { - s: "SAME" + s: "VALID" } } attr { @@ -1311,7 +1311,7 @@ node { attr { key: "padding" value { - s: "SAME" + s: "VALID" } } attr { @@ -2337,6 +2337,12 @@ node { i: 400 } } + attr { + key: "clip" + value { + b: true + } + } } node { name: "reshape_before_softmax" diff --git a/samples/dnn/face_detector/test.prototxt b/samples/dnn/face_detector/test.prototxt index f723f3d113..b441698eb0 100644 --- a/samples/dnn/face_detector/test.prototxt +++ b/samples/dnn/face_detector/test.prototxt @@ -917,7 +917,7 @@ layer { } convolution_param { num_output: 128 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { @@ -983,7 +983,7 @@ layer { } convolution_param { num_output: 128 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { @@ -1810,6 +1810,7 @@ layer { code_type: CENTER_SIZE keep_top_k: 200 confidence_threshold: 0.01 + clip: 1 } } layer { diff --git a/samples/dnn/face_detector/train.prototxt b/samples/dnn/face_detector/train.prototxt index feec4000d5..d2b8167ca9 100644 --- a/samples/dnn/face_detector/train.prototxt +++ b/samples/dnn/face_detector/train.prototxt @@ -1086,7 +1086,7 @@ layer { } convolution_param { num_output: 128 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler { @@ -1600,7 +1600,7 @@ layer { } convolution_param { num_output: 16 - pad: 1 + pad: 0 kernel_size: 3 stride: 1 weight_filler {