Skip to content

Commit 3ec4d03

Browse files
Merge pull request #18 from matlab-deep-learning/bugfix/selectStrongestOrder/17
Fixes issue with ordering of boxes and landmarks
2 parents 3240147 + 423a49f commit 3ec4d03

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

code/mtcnn/+mtcnn/Detector.m

+8-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
landmarks = cat(3, x, y);
127127
landmarks(probs(:, 2) < obj.ConfidenceThresholds(3), :, :) = [];
128128

129-
[scores, bboxes] = obj.processOutputs(probs, correction, bboxes, 3);
129+
[scores, bboxes, landmarks] = obj.processOutputs(probs, correction, bboxes, 3, landmarks);
130130

131131
% Gather and cast the outputs
132132
bboxes= gather(double(bboxes));
@@ -151,17 +151,20 @@
151151
cropped = mtcnn.util.cropImage(im, bboxes, outputSize);
152152
end
153153

154-
function [scores, bboxes] = ...
155-
processOutputs(obj, probs, correction, bboxes, netIdx)
154+
function [scores, bboxes, landmarks] = ...
155+
processOutputs(obj, probs, correction, bboxes, netIdx, landmarks)
156156
% processOutputs Post-process the output values.
157157
faceProbs = probs(:, 2);
158158
bboxes = mtcnn.util.applyCorrection(bboxes, correction);
159159
bboxes(faceProbs < obj.ConfidenceThresholds(netIdx), :) = [];
160-
scores = faceProbs(faceProbs > obj.ConfidenceThresholds(netIdx));
160+
scores = faceProbs(faceProbs >= obj.ConfidenceThresholds(netIdx));
161161
if ~isempty(scores)
162-
[bboxes, ~] = selectStrongestBbox(gather(bboxes), scores, ...
162+
[bboxes, scores, index] = selectStrongestBbox(gather(bboxes), scores, ...
163163
"RatioType", "Min", ...
164164
"OverlapThreshold", obj.NmsThresholds(netIdx));
165+
if netIdx == 3
166+
landmarks = landmarks(index, :, :);
167+
end
165168
end
166169
end
167170

test/+tests/DetectorTest.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,4 @@ function testGpuDetect(test, imageTypeConversion, useDagNet)
131131
test.verifyEqual(landmarks, test.Reference.landmarks, "RelTol", 1e-1);
132132
end
133133
end
134-
end
134+
end

test/+tests/RegressionTest.m

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
classdef RegressionTest < matlab.unittest.TestCase
2+
% Test cases for known bugs that have been fixed
3+
4+
% Copyright 2020 The MathWorks, Inc.
5+
6+
methods (Test)
7+
function testSelectStrongestBug(test)
8+
% GitHub issue #17
9+
im = imread("visionteam1.jpg");
10+
11+
[bboxes, scores, landmarks] = mtcnn.detectFaces(im, "ConfidenceThresholds", repmat(0.01, [3, 1]));
12+
for iBox = 1:size(bboxes, 1)
13+
test.assertInBox(landmarks(iBox, :, :), bboxes(iBox, :));
14+
end
15+
end
16+
end
17+
18+
methods
19+
function assertInBox(test, landmarks, box)
20+
% check that all landmarks are within the bounding box
21+
tf = all(inpolygon(landmarks(1, :, 1), ...
22+
landmarks(1, :, 2), ...
23+
[box(1), box(1) + box(3), box(1) + box(3), box(1)], ...
24+
[box(2), box(2), box(2) + box(4), box(2) + box(4)]));
25+
test.assertTrue(tf, "Landmarks should all be inside bounding box");
26+
end
27+
end
28+
29+
end

0 commit comments

Comments
 (0)