[moco-tf] Fix pad for TFAvgPool in fix shape (#6225)
author박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Mon, 5 Aug 2019 23:25:10 +0000 (08:25 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 5 Aug 2019 23:25:10 +0000 (08:25 +0900)
This will merge fix pad for TFAvgPool node in fix shape transform

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

index 6aa7d46..5380100 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "Annotations/ConcatData.h"
 #include "Annotations/PaddingData.h"
+#include "Annotations/PadData.h"
 #include "Annotations/ShapeInferenceData.h"
 #include "Annotations/StrideData.h"
 #include "Annotations/WindowData.h"
@@ -721,7 +722,29 @@ 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));
+
+  assert(node->annot<PadData>() != nullptr);
+
   INFO(l) << "Fix TFAvgPool shape = ifm" << value_feature_shape << " --> ofm" << ofm_feature_shape;
+  INFO(l) << "              pad = " << *node->annot<PadData>();
 
   return true;
 }