Skip to content

Commit 15df161

Browse files
committed
Merge pull request opencv#9959 from dkurt:reset_detection_outputs
2 parents 988a562 + 03cefa7 commit 15df161

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

modules/dnn/src/layers/detection_output_layer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ class DetectionOutputLayerImpl : public DetectionOutputLayer
240240

241241
if (numKept == 0)
242242
{
243+
// Set confidences to zeros.
244+
Range ranges[] = {Range::all(), Range::all(), Range::all(), Range(2, 3)};
245+
outputs[0](ranges).setTo(0);
243246
return;
244247
}
245248
int outputShape[] = {1, 1, (int)numKept, 7};

modules/dnn/test/test_caffe_importer.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,35 @@ TEST(Reproducibility_SSD, Accuracy)
139139
normAssert(ref, out);
140140
}
141141

142+
TEST(Reproducibility_MobileNet_SSD, Accuracy)
143+
{
144+
const string proto = findDataFile("dnn/MobileNetSSD_deploy.prototxt", false);
145+
const string model = findDataFile("dnn/MobileNetSSD_deploy.caffemodel", false);
146+
Net net = readNetFromCaffe(proto, model);
147+
148+
Mat sample = imread(_tf("street.png"));
149+
150+
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
151+
net.setInput(inp);
152+
Mat out = net.forward();
153+
154+
Mat ref = blobFromNPY(_tf("mobilenet_ssd_caffe_out.npy"));
155+
normAssert(ref, out);
156+
157+
// Check that detections aren't preserved.
158+
inp.setTo(0.0f);
159+
net.setInput(inp);
160+
out = net.forward();
161+
162+
const int numDetections = out.size[2];
163+
ASSERT_NE(numDetections, 0);
164+
for (int i = 0; i < numDetections; ++i)
165+
{
166+
float confidence = out.ptr<float>(0, 0, i)[2];
167+
ASSERT_EQ(confidence, 0);
168+
}
169+
}
170+
142171
TEST(Reproducibility_ResNet50, Accuracy)
143172
{
144173
Net net = readNetFromCaffe(findDataFile("dnn/ResNet-50-deploy.prototxt", false),

0 commit comments

Comments
 (0)