[enco.caffe] Support kernel_h/kernel_w paramaters (#1289)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 3 Sep 2018 01:38:07 +0000 (10:38 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 3 Sep 2018 01:38:07 +0000 (10:38 +0900)
With this commit, ConvolutionSpec is now able to recoginize kernel_h and
kernel_w parameters.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/frontend/caffe/src/ConvolutionSpec.cpp
contrib/enco/frontend/caffe/src/ConvolutionSpec.test.cpp

index 3c5e26b..6ff0006 100644 (file)
@@ -106,6 +106,18 @@ uint32_t ConvolutionSpec::ker_dim(uint32_t spatial_axis) const
   assert(spatial_axis < num_spatial_axes());
   if (_param.kernel_size().size() == 0)
   {
+    if (_param.has_kernel_h() && (spatial_axis == 0))
+    {
+      assert(num_spatial_axes() == 2);
+      return _param.kernel_h();
+    }
+
+    if (_param.has_kernel_w() && (spatial_axis == 1))
+    {
+      assert(num_spatial_axes() == 2);
+      return _param.kernel_w();
+    }
+
     return 0;
   }
 
index a59634b..8599d6c 100644 (file)
@@ -278,3 +278,57 @@ TEST_F(ConvolutionSpecTest, conv_pad)
     ASSERT_EQ(expected, obtained);
   }
 }
+
+namespace
+{
+// clang-format off
+const char *conv_ker_hw = STRING(
+layer {
+  name: "data"
+  type: "Input"
+  top: "data"
+  input_param {
+    shape: { dim: 1 dim: 3 dim: 16 dim: 16 }
+  }
+}
+layer {
+  name: "conv"
+  type: "Convolution"
+  bottom: "data"
+  top: "conv"
+  convolution_param {
+    bias_term: false
+    num_output: 2
+    kernel_h: 3
+    kernel_w: 1
+  }
+}
+);
+// clang-format on
+} // namespace
+
+TEST_F(ConvolutionSpecTest, conv_ker_hw)
+{
+  ::caffe::NetParameter param;
+
+  ASSERT_TRUE(load(conv_ker_hw, param));
+
+  ::caffe::Net<float> net{param};
+
+  const tensor::Shape ifm_shape{1, 3, 16, 16};
+  ConvolutionSpec spec{param.layer(1).convolution_param()};
+
+  spec.ifm_shape(ifm_shape);
+
+  // Check 'pad'
+  ASSERT_EQ(spec.ker_dim(0), 3);
+  ASSERT_EQ(spec.ker_dim(1), 1);
+
+  // Check 'ofm_shape'
+  {
+    auto expected = as_tensor_shape(net.blob_by_name("conv")->shape());
+    auto obtained = spec.ofm_shape();
+
+    ASSERT_EQ(expected, obtained);
+  }
+}