Skip to content

Commit 00d2f34

Browse files
committed
ocl fix for detection_output and prior_box layer
Signed-off-by: Li Peng <[email protected]>
1 parent 7474ad8 commit 00d2f34

File tree

3 files changed

+39
-10
lines changed

3 files changed

+39
-10
lines changed

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;

0 commit comments

Comments
 (0)