Skip to content

Commit 7e3e914

Browse files
committed
dnn: add an accuracy test for NMS
1 parent c704942 commit 7e3e914

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

modules/dnn/src/layers/detection_output_layer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#include <float.h>
4646
#include <string>
4747
#include <caffe.pb.h>
48-
#include <opencv2/dnn/nms.inl.hpp>
48+
#include "../nms.inl.hpp"
4949

5050
namespace cv
5151
{

modules/dnn/src/nms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Third party copyrights are property of their respective owners.
77

88
#include "precomp.hpp"
9-
#include <opencv2/dnn/nms.inl.hpp>
9+
#include <nms.inl.hpp>
1010

1111
namespace cv
1212
{
File renamed without changes.

modules/dnn/test/test_nms.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
//
5+
// Copyright (C) 2017, Intel Corporation, all rights reserved.
6+
// Third party copyrights are property of their respective owners.
7+
8+
#include "test_precomp.hpp"
9+
10+
namespace cvtest
11+
{
12+
13+
TEST(NMS, Accuracy)
14+
{
15+
//reference results obtained using tf.image.non_max_suppression with iou_threshold=0.5
16+
std::string dataPath = findDataFile("dnn/nms_reference.yml");
17+
FileStorage fs(dataPath, FileStorage::READ);
18+
19+
std::vector<Rect> bboxes;
20+
std::vector<float> scores;
21+
std::vector<int> ref_indices;
22+
23+
fs["boxes"] >> bboxes;
24+
fs["probs"] >> scores;
25+
fs["output"] >> ref_indices;
26+
27+
const float nms_thresh = .5f;
28+
const float score_thresh = .01f;
29+
std::vector<int> indices;
30+
cv::dnn::NMSBoxes(bboxes, scores, score_thresh, nms_thresh, indices);
31+
32+
ASSERT_EQ(ref_indices.size(), indices.size());
33+
34+
std::sort(indices.begin(), indices.end());
35+
std::sort(ref_indices.begin(), ref_indices.end());
36+
37+
for(size_t i = 0; i < indices.size(); i++)
38+
ASSERT_EQ(indices[i], ref_indices[i]);
39+
}
40+
41+
}//cvtest

0 commit comments

Comments
 (0)