[moco-tf] Use calc_annot_paddata for fix pad of TF dialect nods (#6301)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 7 Aug 2019 06:41:48 +0000 (15:41 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 7 Aug 2019 06:41:48 +0000 (15:41 +0900)
This will change to use calc_annot_paddata() method to fix pad in FixShapeInference for TFAvgPool node

Signed-off-by: SaeHie Park <saehie.park@samsung.com>
compiler/moco-tf/src/Transforms/FixShapeTransform.cpp

index a13fe84..65ec1e5 100644 (file)
@@ -766,26 +766,11 @@ bool fix_shape(moco::tf::TFAvgPool *node)
   as_tensor_shape(*shape_data.get(), ofm_feature_shape, node->data_layout());
   node->annot(std::move(shape_data));
 
-  // PadData should be null
-  assert(node->annot<PadData>() == nullptr);
-
-  // calculate padding height, width
-  int32_t i_height = (output_height - 1) * stride_height + effective_window_height - input_height;
-  int32_t i_width = (output_width - 1) * stride_width + effective_window_width - input_width;
-  uint32_t pad_height = i_height >= 0 ? i_height : 0U;
-  uint32_t pad_width = i_width >= 0 ? i_width : 0U;
-
-  // annotation of pad data
-  auto pad_data = stdex::make_unique<PadData>();
-
-  pad_data->pad()->top(pad_height / 2);
-  pad_data->pad()->bottom(pad_height - pad_data->pad()->top());
-  pad_data->pad()->left(pad_width / 2);
-  pad_data->pad()->right(pad_width - pad_data->pad()->left());
-
-  node->annot(std::move(pad_data));
+  FixPadContext ctx = {
+      input_height,  input_width,  output_height,           output_width,
+      stride_height, stride_width, effective_window_height, effective_window_width};
 
-  assert(node->annot<PadData>() != nullptr);
+  calc_annot_paddata(node, ctx);
 
   INFO(l) << "Fix TFAvgPool shape = ifm" << value_feature_shape << " --> ofm" << ofm_feature_shape;
   INFO(l) << "              pad = " << *node->annot<PadData>();