Skip to content

Commit 3e33820

Browse files
committed
Merge pull request opencv#10104 from wzw-intel:fusion_debug
2 parents 73d4f12 + 394101d commit 3e33820

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class OCL4DNNConvSpatial
302302
std::stringstream options_;
303303
cv::ocl::ProgramSource src_;
304304
int32_t prev_kernel_type_;
305-
bool negative_slope_;
305+
float negative_slope_;
306306
UMat negative_slope_umat_;
307307
ocl4dnnFusedActiv_t fused_activ_;
308308
};

modules/dnn/test/test_darknet_importer.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#include "test_precomp.hpp"
4545
#include <opencv2/dnn/shape_utils.hpp>
4646
#include <algorithm>
47+
#include <opencv2/core/ocl.hpp>
48+
#include <opencv2/ts/ocl_test.hpp>
4749

4850
namespace cvtest
4951
{
@@ -69,6 +71,64 @@ TEST(Test_Darknet, read_yolo_voc)
6971
ASSERT_FALSE(net.empty());
7072
}
7173

74+
OCL_TEST(Reproducibility_TinyYoloVoc, Accuracy)
75+
{
76+
Net net;
77+
{
78+
const string cfg = findDataFile("dnn/tiny-yolo-voc.cfg", false);
79+
const string model = findDataFile("dnn/tiny-yolo-voc.weights", false);
80+
net = readNetFromDarknet(cfg, model);
81+
ASSERT_FALSE(net.empty());
82+
}
83+
84+
net.setPreferableBackend(DNN_BACKEND_DEFAULT);
85+
net.setPreferableTarget(DNN_TARGET_OPENCL);
86+
87+
// dog416.png is dog.jpg that resized to 416x416 in the lossless PNG format
88+
Mat sample = imread(_tf("dog416.png"));
89+
ASSERT_TRUE(!sample.empty());
90+
91+
Size inputSize(416, 416);
92+
93+
if (sample.size() != inputSize)
94+
resize(sample, sample, inputSize);
95+
96+
net.setInput(blobFromImage(sample, 1 / 255.F), "data");
97+
Mat out = net.forward("detection_out");
98+
99+
Mat detection;
100+
const float confidenceThreshold = 0.24;
101+
102+
for (int i = 0; i < out.rows; i++) {
103+
const int probability_index = 5;
104+
const int probability_size = out.cols - probability_index;
105+
float *prob_array_ptr = &out.at<float>(i, probability_index);
106+
size_t objectClass = std::max_element(prob_array_ptr, prob_array_ptr + probability_size) - prob_array_ptr;
107+
float confidence = out.at<float>(i, (int)objectClass + probability_index);
108+
109+
if (confidence > confidenceThreshold)
110+
detection.push_back(out.row(i));
111+
}
112+
113+
// obtained by: ./darknet detector test ./cfg/voc.data ./cfg/tiny-yolo-voc.cfg ./tiny-yolo-voc.weights -thresh 0.24 ./dog416.png
114+
// There are 2 objects (6-car, 11-dog) with 25 values for each:
115+
// { relative_center_x, relative_center_y, relative_width, relative_height, unused_t0, probability_for_each_class[20] }
116+
float ref_array[] = {
117+
0.736762F, 0.239551F, 0.315440F, 0.160779F, 0.761977F, 0.000000F, 0.000000F, 0.000000F, 0.000000F,
118+
0.000000F, 0.000000F, 0.761967F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F,
119+
0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F,
120+
121+
0.287486F, 0.653731F, 0.315579F, 0.534527F, 0.782737F, 0.000000F, 0.000000F, 0.000000F, 0.000000F,
122+
0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.780595F,
123+
0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F, 0.000000F
124+
};
125+
126+
const int number_of_objects = 2;
127+
Mat ref(number_of_objects, sizeof(ref_array) / (number_of_objects * sizeof(float)), CV_32FC1, &ref_array);
128+
129+
normAssert(ref, detection);
130+
}
131+
72132
TEST(Reproducibility_TinyYoloVoc, Accuracy)
73133
{
74134
Net net;

0 commit comments

Comments
 (0)