[Pooling2D] Change warning to error at init accepted/tizen/unified/20210331.054231 submit/tizen/20210330.110555
authorJihoon Lee <jhoon.it.lee@samsung.com>
Tue, 30 Mar 2021 05:48:40 +0000 (14:48 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Tue, 30 Mar 2021 07:24:29 +0000 (16:24 +0900)
For global_* pooling change warning to error for some parameter check

**Self evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test: [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Jihoon Lee <jhoon.it.lee@samsung.com>
nntrainer/layers/pooling2d_layer.cpp
nntrainer/layers/pooling2d_layer.h
test/unittest/unittest_nntrainer_appcontext.cpp
test/unittest/unittest_nntrainer_layers.cpp

index 10da0503ac5a71d60ce7ee2a4c7992a9fd33c7c4..31c96fcba019b6c2fc2ec389d474c4f3a79e7655 100644 (file)
@@ -34,6 +34,11 @@ int Pooling2DLayer::initialize(Manager &manager) {
     return ML_ERROR_INVALID_PARAMETER;
   }
 
+  if (input_dim.size() != 1) {
+    ml_loge("[Pooling2D] pooling layer only accepts number of one layer");
+    return ML_ERROR_INVALID_PARAMETER;
+  }
+
   TensorDim &in_dim = input_dim[0];
   TensorDim &out_dim = output_dim[0];
 
@@ -43,23 +48,22 @@ int Pooling2DLayer::initialize(Manager &manager) {
 
   if (pooling_type == PoolingType::global_max ||
       pooling_type == PoolingType::global_average) {
-    if (pool_size[0] != in_dim.height() || pool_size[1] != in_dim.width()) {
-      ml_logw(
+    if (pool_size[0] != 0 || pool_size[1] != 0) {
+      ml_loge(
         "[Pooling2D] global_max, global_average does not accept pool size");
-      pool_size[0] = in_dim.height();
-      pool_size[1] = in_dim.width();
+      return ML_ERROR_INVALID_PARAMETER;
     }
+    pool_size[0] = in_dim.height();
+    pool_size[1] = in_dim.width();
 
     if (padding[0] != 0 || padding[1] != 0) {
-      ml_logw("[Pooling2D] global_max, global_average does not accept padding");
-      padding[0] = 0;
-      padding[1] = 0;
+      ml_loge("[Pooling2D] global_max, global_average does not accept padding");
+      return ML_ERROR_INVALID_PARAMETER;
     }
 
     if (stride[0] != 1 || stride[1] != 1) {
-      ml_logw("[Pooling2D] global_max, global_average does not accept stride");
-      stride[0] = 1;
-      stride[1] = 1;
+      ml_loge("[Pooling2D] global_max, global_average does not accept stride");
+      return ML_ERROR_INVALID_PARAMETER;
     }
   }
 
index cc74a6737aa8cbf45fde3479f17a5e55daffab9c..3b464b419a77286051df6921acb21dda33c6a112 100644 (file)
@@ -141,7 +141,17 @@ private:
   std::array<unsigned int, POOLING2D_DIM> padding;
   std::vector<int>
     max_idx; /**< in case of max pool, idx that points to the first max item
-                  in case of avearge pol, effective average counter */
+                  in case of avearge pol, effective average counter
+                  effective average counter is number of patches actually
+                  counted into when calculating the average
+                  // clang-format off
+                  eg) pooling of below
+                  x x x
+                  x 3 3
+                  x 3 3
+                  = 12 / 4 = 3
+                  // clang-format on
+              */
   std::vector<std::vector<int>> max_idx_global;
   PoolingType pooling_type;
 
index 8d212cb771d25726c6e9dabd58e26df90977e784..25f37c511627ccc287eb3b54d5b63a064bd71217 100644 (file)
@@ -104,7 +104,8 @@ public:
 
   void addOptimizerVariable(std::vector<nntrainer::Weight> &params) override {}
 
-  void setProperty(const PropertyType type, const std::string &value = "") override {}
+  void setProperty(const PropertyType type,
+                   const std::string &value = "") override {}
 
   void checkValidation() const override {}
 
@@ -134,7 +135,8 @@ public:
 
   int setProperty(std::vector<std::string> values) override { return 1; }
 
-  void setProperty(const PropertyType type, const std::string &value = "") override {}
+  void setProperty(const PropertyType type,
+                   const std::string &value = "") override {}
 
   int checkValidation() override { return 1; }
 
index f4ec5b74e33bb33d1d4a218090bcc8c8d19abe81..40880ad280c271b690e0b6a8a980db19461cfd56 100644 (file)
@@ -1803,7 +1803,7 @@ TEST_F(nntrainer_Pooling2DLayer, backwarding_02_p) {
 TEST_F(nntrainer_Pooling2DLayer, backwarding_03_p) {
   resetLayer();
   setInputDim("2:5:5");
-  setProperty("pool_size=2,2 | stride=1,1 | padding=0,0 | pooling=global_max");
+  setProperty("pooling=global_max");
   initialize();
   allocateMemory();
 
@@ -1826,8 +1826,7 @@ TEST_F(nntrainer_Pooling2DLayer, backwarding_03_p) {
 
 TEST_F(nntrainer_Pooling2DLayer, backwarding_04_p) {
   setInputDim("2:5:5");
-  setProperty(
-    "pool_size=2,2 | stride=1,1 | padding=0,0 | pooling=global_average");
+  setProperty("pooling=global_average");
   initialize();
   allocateMemory();
   loadFile("tc_pooling2d_1.in", in);