Merge pull request #10922 from pengli:dnn
authorLi, Peng <peng.li@intel.com>
Thu, 22 Feb 2018 18:01:12 +0000 (02:01 +0800)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 22 Feb 2018 18:01:12 +0000 (21:01 +0300)
* ave pooling ocl fix

support the padded area control in ave pooling

Signed-off-by: Li Peng <peng.li@intel.com>
* warning fix: ununitialized field

modules/dnn/src/layers/pooling_layer.cpp
modules/dnn/src/ocl4dnn/include/ocl4dnn.hpp
modules/dnn/src/ocl4dnn/src/ocl4dnn_pool.cpp
modules/dnn/src/opencl/ocl4dnn_pooling.cl

index ee552b5..3cdc786 100644 (file)
@@ -145,9 +145,6 @@ public:
         inps.getUMatVector(inputs);
         outs.getUMatVector(outputs);
 
-        if (type == AVE && padMode == "SAME")
-            return false;
-
         if (poolOp.empty())
         {
             OCL4DNNPoolConfig config;
@@ -161,6 +158,7 @@ public:
             config.pool_method = type == MAX ? LIBDNN_POOLING_METHOD_MAX :
                                 (type == AVE ? LIBDNN_POOLING_METHOD_AVE :
                                                LIBDNN_POOLING_METHOD_STO);
+            config.avePoolPaddedArea = avePoolPaddedArea;
             poolOp = Ptr<OCL4DNNPool<float> >(new OCL4DNNPool<float>(config));
         }
 
index 93ac1a2..70ced11 100644 (file)
@@ -344,7 +344,8 @@ struct OCL4DNNPoolConfig
         dilation(1, 1),
         channels(0),
         pool_method(LIBDNN_POOLING_METHOD_MAX),
-        global_pooling(false)
+        global_pooling(false),
+        avePoolPaddedArea(false)
     {}
     MatShape in_shape;
     MatShape out_shape;
@@ -356,6 +357,7 @@ struct OCL4DNNPoolConfig
     int channels;
     ocl4dnnPoolingMethod_t pool_method; // = LIBDNN_POOLING_METHOD_MAX;
     bool global_pooling; // = false;
+    bool avePoolPaddedArea;
 };
 
 template<typename Dtype>
@@ -388,6 +390,7 @@ class OCL4DNNPool
         int32_t width_;
         int32_t pooled_height_;
         int32_t pooled_width_;
+        bool avePoolPaddedArea;
 };
 
 struct OCL4DNNInnerProductConfig
index 759408c..4d4ea9e 100644 (file)
@@ -56,6 +56,7 @@ OCL4DNNPool<Dtype>::OCL4DNNPool(OCL4DNNPoolConfig config)
 
     channels_ = config.channels;
     pool_method_ = config.pool_method;
+    avePoolPaddedArea = config.avePoolPaddedArea;
 
     for (int i = 0; i < spatial_dims; ++i)
     {
@@ -143,10 +144,11 @@ bool OCL4DNNPool<Dtype>::Forward(const UMat& bottom,
                 ocl::dnn::ocl4dnn_pooling_oclsrc,
                 format("-D KERNEL_AVE_POOL=1 -D KERNEL_W=%d -D KERNEL_H=%d"
                        " -D STRIDE_W=%d -D STRIDE_H=%d"
-                       " -D PAD_W=%d -D PAD_H=%d",
+                       " -D PAD_W=%d -D PAD_H=%d%s",
                        kernel_w_, kernel_h_,
                        stride_w_, stride_h_,
-                       pad_w_, pad_h_
+                       pad_w_, pad_h_,
+                       avePoolPaddedArea ? " -D AVE_POOL_PADDING_AREA" : ""
                 ));
 
             if (oclk_ave_pool_forward.empty())
index bb3ba8a..13e4319 100644 (file)
@@ -114,11 +114,20 @@ __kernel void TEMPLATE(ave_pool_forward, Dtype)(
       int wstart = pw * STRIDE_W - PAD_W;
       int hend = min(hstart + KERNEL_H, height + PAD_H);
       int wend = min(wstart + KERNEL_W, width + PAD_W);
-      const int pool_size = (hend - hstart) * (wend - wstart);
+      int pool_size;
+#ifdef AVE_POOL_PADDING_AREA
+      pool_size = (hend - hstart) * (wend - wstart);
       hstart = max(hstart, (int)0);
       wstart = max(wstart, (int)0);
       hend = min(hend, height);
       wend = min(wend, width);
+#else
+      hstart = max(hstart, (int)0);
+      wstart = max(wstart, (int)0);
+      hend = min(hend, height);
+      wend = min(wend, width);
+      pool_size = (hend - hstart) * (wend - wstart);
+#endif
       Dtype aveval = 0;
       __global const Dtype* bottom_slice = bottom_data
           + (n * channels + c) * height * width;