@@ -106,6 +106,7 @@ class PoolingLayerImpl : public PoolingLayer
106
106
setParamsFrom (params);
107
107
ceilMode = params.get <bool >(" ceil_mode" , true );
108
108
spatialScale = params.get <float >(" spatial_scale" , 1 );
109
+ avePoolPaddedArea = params.get <bool >(" ave_pool_padded_area" , true );
109
110
}
110
111
111
112
#ifdef HAVE_OPENCL
@@ -259,7 +260,7 @@ class PoolingLayerImpl : public PoolingLayer
259
260
const Mat* src, *rois;
260
261
Mat *dst, *mask;
261
262
Size kernel, stride, pad;
262
- String padMode ;
263
+ bool avePoolPaddedArea ;
263
264
int nstripes;
264
265
bool computeMaxIdx;
265
266
std::vector<int > ofsbuf;
@@ -270,7 +271,7 @@ class PoolingLayerImpl : public PoolingLayer
270
271
computeMaxIdx (0 ), poolingType(MAX), spatialScale(0 ) {}
271
272
272
273
static void run (const Mat& src, const Mat& rois, Mat& dst, Mat& mask, Size kernel,
273
- Size stride, Size pad, String padMode , int poolingType, float spatialScale,
274
+ Size stride, Size pad, bool avePoolPaddedArea , int poolingType, float spatialScale,
274
275
bool computeMaxIdx, int nstripes)
275
276
{
276
277
CV_Assert (src.isContinuous (), dst.isContinuous (),
@@ -289,7 +290,7 @@ class PoolingLayerImpl : public PoolingLayer
289
290
p.kernel = kernel;
290
291
p.stride = stride;
291
292
p.pad = pad;
292
- p.padMode = padMode ;
293
+ p.avePoolPaddedArea = avePoolPaddedArea ;
293
294
p.nstripes = nstripes;
294
295
p.computeMaxIdx = computeMaxIdx;
295
296
p.poolingType = poolingType;
@@ -369,6 +370,7 @@ class PoolingLayerImpl : public PoolingLayer
369
370
yend = min (ystart + kernel_h, inp_height + pad_h);
370
371
srcData = src->ptr <float >(n, c);
371
372
}
373
+ int ydelta = yend - ystart;
372
374
ystart = max (ystart, 0 );
373
375
yend = min (yend, inp_height);
374
376
float *dstData = dst->ptr <float >(n, c, y0);
@@ -532,14 +534,14 @@ class PoolingLayerImpl : public PoolingLayer
532
534
}
533
535
else if (poolingType == AVE)
534
536
{
535
- bool isSamePad = padMode == " SAME" ;
536
537
for ( ; x0 < x1; x0++ )
537
538
{
538
539
int xstart = x0 * stride_w - pad_w;
539
540
int xend = min (xstart + kernel_w, inp_width + pad_w);
541
+ int xdelta = xend - xstart;
540
542
xstart = max (xstart, 0 );
541
543
xend = min (xend, inp_width);
542
- float inv_kernel_area = isSamePad ? ( yend - ystart) * (xend - xstart) : kernel. area ( );
544
+ float inv_kernel_area = avePoolPaddedArea ? xdelta * ydelta : (( yend - ystart) * (xend - xstart));
543
545
inv_kernel_area = 1.0 / inv_kernel_area;
544
546
#if CV_SIMD128
545
547
if ( xstart > 0 && x0 + 7 < x1 && (x0 + 7 ) * stride_w - pad_w + kernel_w < inp_width )
@@ -651,21 +653,21 @@ class PoolingLayerImpl : public PoolingLayer
651
653
{
652
654
const int nstripes = getNumThreads ();
653
655
Mat rois;
654
- PoolingInvoker::run (src, rois, dst, mask, kernel, stride, pad, padMode , type, spatialScale, computeMaxIdx, nstripes);
656
+ PoolingInvoker::run (src, rois, dst, mask, kernel, stride, pad, avePoolPaddedArea , type, spatialScale, computeMaxIdx, nstripes);
655
657
}
656
658
657
659
void avePooling (Mat &src, Mat &dst)
658
660
{
659
661
const int nstripes = getNumThreads ();
660
662
Mat rois, mask;
661
- PoolingInvoker::run (src, rois, dst, mask, kernel, stride, pad, padMode , type, spatialScale, computeMaxIdx, nstripes);
663
+ PoolingInvoker::run (src, rois, dst, mask, kernel, stride, pad, avePoolPaddedArea , type, spatialScale, computeMaxIdx, nstripes);
662
664
}
663
665
664
666
void roiPooling (const Mat &src, const Mat &rois, Mat &dst)
665
667
{
666
668
const int nstripes = getNumThreads ();
667
669
Mat mask;
668
- PoolingInvoker::run (src, rois, dst, mask, kernel, stride, pad, padMode , type, spatialScale, computeMaxIdx, nstripes);
670
+ PoolingInvoker::run (src, rois, dst, mask, kernel, stride, pad, avePoolPaddedArea , type, spatialScale, computeMaxIdx, nstripes);
669
671
}
670
672
671
673
virtual Ptr<BackendNode> initMaxPoolingHalide (const std::vector<Ptr<BackendWrapper> > &inputs)
0 commit comments