Skip to content

Commit cff7960

Browse files
committed
Merge pull request opencv#10854 from pengli:dnn
2 parents c434198 + 80d1f2d commit cff7960

File tree

6 files changed

+50
-16
lines changed

6 files changed

+50
-16
lines changed

modules/dnn/src/layers/convolution_layer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,13 @@ class ConvolutionLayerImpl : public BaseConvolutionLayerImpl
824824
for (int i = 0; i < inputs.size(); ++i)
825825
CV_Assert(inputs[i].u != outputs[0].u);
826826

827+
int inpH = inputs[0].size[2];
828+
int inpW = inputs[0].size[3];
829+
int out_h = (inpH + 2 * pad.height - (dilation.height * (kernel.height - 1) + 1)) / stride.height + 1;
830+
int out_w = (inpW + 2 * pad.width - (dilation.width * (kernel.width - 1) + 1)) / stride.width + 1;
831+
if (out_h != outputs[0].size[2] || out_w != outputs[0].size[3])
832+
return false;
833+
827834
int group = inputs[0].size[1] / umat_blobs[0].size[1];
828835

829836
if (convolutionOp.empty())

modules/dnn/src/layers/detection_output_layer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ class DetectionOutputLayerImpl : public DetectionOutputLayer
249249
kernel.set(6, (int)num_loc_classes);
250250
kernel.set(7, (int)background_label_id);
251251
kernel.set(8, (int)clip);
252-
kernel.set(9, ocl::KernelArg::PtrWriteOnly(outmat));
252+
kernel.set(9, (int)_locPredTransposed);
253+
kernel.set(10, ocl::KernelArg::PtrWriteOnly(outmat));
253254

254255
if (!kernel.run(1, &nthreads, NULL, false))
255256
return false;

modules/dnn/src/layers/prior_box_layer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,17 @@ class PriorBoxLayerImpl : public PriorBoxLayer
317317
variance.copyTo(umat_variance);
318318

319319
int real_numPriors = _numPriors >> (_offsetsX.size() - 1);
320-
umat_scales = UMat(1, &real_numPriors, CV_32F, 1.0f);
320+
if (_scales.empty())
321+
{
322+
_scales.resize(real_numPriors, 1.0f);
323+
umat_scales = UMat(1, &real_numPriors, CV_32F, 1.0f);
324+
}
325+
else
326+
{
327+
CV_Assert(_scales.size() == real_numPriors);
328+
Mat scales(1, _scales.size(), CV_32FC1, &_scales[0]);
329+
scales.copyTo(umat_scales);
330+
}
321331
}
322332

323333
size_t nthreads = _layerHeight * _layerWidth;

modules/dnn/src/opencl/detection_output.cl

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ __kernel void DecodeBBoxesCORNER(const int nthreads,
5151
const int num_loc_classes,
5252
const int background_label_id,
5353
const int clip_bbox,
54+
const int locPredTransposed,
5455
__global Dtype* bbox_data)
5556
{
5657
for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))
@@ -75,10 +76,18 @@ __kernel void DecodeBBoxesCORNER(const int nthreads,
7576
bbox_vec = loc_vec * prior_variance;
7677
}
7778

78-
bbox_xmin = bbox_vec.x;
79-
bbox_ymin = bbox_vec.y;
80-
bbox_xmax = bbox_vec.z;
81-
bbox_ymax = bbox_vec.w;
79+
if (locPredTransposed)
80+
{
81+
bbox_ymin = bbox_vec.x;
82+
bbox_xmin = bbox_vec.y;
83+
bbox_ymax = bbox_vec.z;
84+
bbox_xmax = bbox_vec.w;
85+
} else {
86+
bbox_xmin = bbox_vec.x;
87+
bbox_ymin = bbox_vec.y;
88+
bbox_xmax = bbox_vec.z;
89+
bbox_ymax = bbox_vec.w;
90+
}
8291

8392
Dtype4 prior_vec = vload4(0, prior_data + p);
8493
Dtype val;
@@ -114,6 +123,7 @@ __kernel void DecodeBBoxesCENTER_SIZE(const int nthreads,
114123
const int num_loc_classes,
115124
const int background_label_id,
116125
const int clip_bbox,
126+
const int locPredTransposed,
117127
__global Dtype* bbox_data)
118128
{
119129
for (int index = get_global_id(0); index < nthreads; index += get_global_size(0))
@@ -138,10 +148,18 @@ __kernel void DecodeBBoxesCENTER_SIZE(const int nthreads,
138148
bbox_vec = loc_vec * prior_variance;
139149
}
140150

141-
bbox_xmin = bbox_vec.x;
142-
bbox_ymin = bbox_vec.y;
143-
bbox_xmax = bbox_vec.z;
144-
bbox_ymax = bbox_vec.w;
151+
if (locPredTransposed)
152+
{
153+
bbox_ymin = bbox_vec.x;
154+
bbox_xmin = bbox_vec.y;
155+
bbox_ymax = bbox_vec.z;
156+
bbox_xmax = bbox_vec.w;
157+
} else {
158+
bbox_xmin = bbox_vec.x;
159+
bbox_ymin = bbox_vec.y;
160+
bbox_xmax = bbox_vec.z;
161+
bbox_ymax = bbox_vec.w;
162+
}
145163

146164
Dtype4 prior_vec = vload4(0, prior_data + p);
147165
Dtype prior_width = prior_vec.z - prior_vec.x;

modules/dnn/test/test_backends.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ TEST_P(DNNTestNetwork, MobileNet_SSD_Caffe)
174174

175175
TEST_P(DNNTestNetwork, MobileNet_SSD_TensorFlow)
176176
{
177-
if (backend == DNN_BACKEND_DEFAULT && target == DNN_TARGET_OPENCL ||
178-
backend == DNN_BACKEND_HALIDE)
179-
throw SkipTestException("");
177+
if (backend == DNN_BACKEND_HALIDE) throw SkipTestException("");
180178
Mat sample = imread(findDataFile("dnn/street.png", false));
181179
Mat inp = blobFromImage(sample, 1.0f / 127.5, Size(300, 300), Scalar(127.5, 127.5, 127.5), false);
182180
processNet("dnn/ssd_mobilenet_v1_coco.pb", "dnn/ssd_mobilenet_v1_coco.pbtxt",

modules/dnn/test/test_tf_importer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
285285
normAssert(detections, ref);
286286
}
287287

288-
OCL_TEST(Test_TensorFlow, DISABLED_MobileNet_SSD)
288+
OCL_TEST(Test_TensorFlow, MobileNet_SSD)
289289
{
290290
std::string netPath = findDataFile("dnn/ssd_mobilenet_v1_coco.pb", false);
291291
std::string netConfig = findDataFile("dnn/ssd_mobilenet_v1_coco.pbtxt", false);
@@ -317,8 +317,8 @@ OCL_TEST(Test_TensorFlow, DISABLED_MobileNet_SSD)
317317
std::vector<Mat> output;
318318
net.forward(output, outNames);
319319

320-
normAssert(target[0].reshape(1, 1), output[0].reshape(1, 1));
321-
normAssert(target[1].reshape(1, 1), output[1].reshape(1, 1), "", 1e-5, 2e-4);
320+
normAssert(target[0].reshape(1, 1), output[0].reshape(1, 1), "", 1e-5, 1.5e-4);
321+
normAssert(target[1].reshape(1, 1), output[1].reshape(1, 1), "", 1e-5, 3e-4);
322322
normAssert(target[2].reshape(1, 1), output[2].reshape(1, 1), "", 4e-5, 1e-2);
323323
}
324324

0 commit comments

Comments
 (0)