Skip to content

Commit 5caf624

Browse files
pli2-intelalalek
authored andcommitted
Merge pull request opencv#10922 from pengli:dnn
* ave pooling ocl fix support the padded area control in ave pooling Signed-off-by: Li Peng <[email protected]> * warning fix: ununitialized field
1 parent eaaba64 commit 5caf624

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

modules/dnn/src/layers/pooling_layer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ class PoolingLayerImpl : public PoolingLayer
145145
inps.getUMatVector(inputs);
146146
outs.getUMatVector(outputs);
147147

148-
if (type == AVE && padMode == "SAME")
149-
return false;
150-
151148
if (poolOp.empty())
152149
{
153150
OCL4DNNPoolConfig config;
@@ -161,6 +158,7 @@ class PoolingLayerImpl : public PoolingLayer
161158
config.pool_method = type == MAX ? LIBDNN_POOLING_METHOD_MAX :
162159
(type == AVE ? LIBDNN_POOLING_METHOD_AVE :
163160
LIBDNN_POOLING_METHOD_STO);
161+
config.avePoolPaddedArea = avePoolPaddedArea;
164162
poolOp = Ptr<OCL4DNNPool<float> >(new OCL4DNNPool<float>(config));
165163
}
166164

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ struct OCL4DNNPoolConfig
344344
dilation(1, 1),
345345
channels(0),
346346
pool_method(LIBDNN_POOLING_METHOD_MAX),
347-
global_pooling(false)
347+
global_pooling(false),
348+
avePoolPaddedArea(false)
348349
{}
349350
MatShape in_shape;
350351
MatShape out_shape;
@@ -356,6 +357,7 @@ struct OCL4DNNPoolConfig
356357
int channels;
357358
ocl4dnnPoolingMethod_t pool_method; // = LIBDNN_POOLING_METHOD_MAX;
358359
bool global_pooling; // = false;
360+
bool avePoolPaddedArea;
359361
};
360362

361363
template<typename Dtype>
@@ -388,6 +390,7 @@ class OCL4DNNPool
388390
int32_t width_;
389391
int32_t pooled_height_;
390392
int32_t pooled_width_;
393+
bool avePoolPaddedArea;
391394
};
392395

393396
struct OCL4DNNInnerProductConfig

modules/dnn/src/ocl4dnn/src/ocl4dnn_pool.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ OCL4DNNPool<Dtype>::OCL4DNNPool(OCL4DNNPoolConfig config)
5656

5757
channels_ = config.channels;
5858
pool_method_ = config.pool_method;
59+
avePoolPaddedArea = config.avePoolPaddedArea;
5960

6061
for (int i = 0; i < spatial_dims; ++i)
6162
{
@@ -143,10 +144,11 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
143144
ocl::dnn::ocl4dnn_pooling_oclsrc,
144145
format("-D KERNEL_AVE_POOL=1 -D KERNEL_W=%d -D KERNEL_H=%d"
145146
" -D STRIDE_W=%d -D STRIDE_H=%d"
146-
" -D PAD_W=%d -D PAD_H=%d",
147+
" -D PAD_W=%d -D PAD_H=%d%s",
147148
kernel_w_, kernel_h_,
148149
stride_w_, stride_h_,
149-
pad_w_, pad_h_
150+
pad_w_, pad_h_,
151+
avePoolPaddedArea ? " -D AVE_POOL_PADDING_AREA" : ""
150152
));
151153

152154
if (oclk_ave_pool_forward.empty())

modules/dnn/src/opencl/ocl4dnn_pooling.cl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,20 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
114114
int wstart = pw * STRIDE_W - PAD_W;
115115
int hend = min(hstart + KERNEL_H, height + PAD_H);
116116
int wend = min(wstart + KERNEL_W, width + PAD_W);
117-
const int pool_size = (hend - hstart) * (wend - wstart);
117+
int pool_size;
118+
#ifdef AVE_POOL_PADDING_AREA
119+
pool_size = (hend - hstart) * (wend - wstart);
118120
hstart = max(hstart, (int)0);
119121
wstart = max(wstart, (int)0);
120122
hend = min(hend, height);
121123
wend = min(wend, width);
124+
#else
125+
hstart = max(hstart, (int)0);
126+
wstart = max(wstart, (int)0);
127+
hend = min(hend, height);
128+
wend = min(wend, width);
129+
pool_size = (hend - hstart) * (wend - wstart);
130+
#endif
122131
Dtype aveval = 0;
123132
__global const Dtype* bottom_slice = bottom_data
124133
+ (n * channels + c) * height * width;

0 commit comments

Comments
 (0)