From: 박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 Date: Fri, 21 Jun 2019 07:41:48 +0000 (+0900) Subject: [moco/tf] support bias in ShapeInferenceData (#3913) X-Git-Tag: nncc_backup~312 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5965244209e22d9c75f2d176d20a549e3724b72f;p=platform%2Fcore%2Fml%2Fnnfw.git [moco/tf] support bias in ShapeInferenceData (#3913) This will introduce bias attribute accessor in ShapeInferenceData Signed-off-by: SaeHie Park --- diff --git a/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.cpp b/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.cpp index 04b5f5a..6f73bd2 100644 --- a/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.cpp +++ b/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.cpp @@ -75,6 +75,18 @@ loco::FilterShape ShapeInferenceData::filter_shape(void) const return shape; } +loco_tobe::BiasShape ShapeInferenceData::bias_shape(void) const +{ + assert(_domain == loco::Domain::Bias); + + loco_tobe::BiasShape shape; + + // Note: this may change when loco::BiasShape becomes available + shape = dim(0); + + return shape; +} + void ShapeInferenceData::feature_shape(const loco::FeatureShape &shape) { _domain = loco::Domain::Feature; @@ -97,5 +109,14 @@ void ShapeInferenceData::filter_shape(const loco::FilterShape &shape) dim(3) = shape.depth(); } +void ShapeInferenceData::bias_shape(const loco_tobe::BiasShape &shape) +{ + _domain = loco::Domain::Bias; + + // Note: this may change when loco::BiasShape becomes available + rank(1); + dim(0) = shape; +} + } // namespace tf } // namespace moco diff --git a/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.h b/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.h index 2d111e1..831e645 100644 --- a/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.h +++ b/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.h @@ -21,6 +21,14 @@ #include +namespace loco_tobe +{ + +// Temporary BiasShape that loco will provide in near future +using BiasShape = loco::Dimension; + +} // namespace loco_tobe + namespace moco { namespace tf @@ -43,9 +51,11 @@ public: loco::TensorShape tensor_shape(void) const; loco::FeatureShape feature_shape(void) const; loco::FilterShape filter_shape(void) const; + loco_tobe::BiasShape bias_shape(void) const; void feature_shape(const loco::FeatureShape &shape); void filter_shape(const loco::FilterShape &shape); + void bias_shape(const loco_tobe::BiasShape &shape); private: // TODO set default as Unknown, setting Tensor is to minimize change diff --git a/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.test.cpp b/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.test.cpp index 1935b0a..89f9b85 100644 --- a/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.test.cpp +++ b/contrib/moco/lib/frontend/tf/src/Annotations/ShapeInferenceData.test.cpp @@ -97,3 +97,38 @@ TEST(TensorFlowFrontend, shapeinferencedata_filter_set) ASSERT_EQ(shapedata.dim(2), 3); ASSERT_EQ(shapedata.dim(3), 4); } + +TEST(TensorFlowFrontend, shapeinferencedata_bias_set) +{ + // Note: this may change when loco::BiasShape becomes available + + loco_tobe::BiasShape bias; + + bias = 3; + + moco::tf::ShapeInferenceData shapedata; + + shapedata.bias_shape(bias); + + ASSERT_EQ(shapedata.rank(), 1); + ASSERT_EQ(shapedata.dim(0), 3); +} + +TEST(TensorFlowFrontend, shapeinferencedata_bias_get) +{ + // Note: this may change when loco::BiasShape becomes available + + // This test is to check bias is stored in first dimension + // for normal case, we shouldn't access directly for bias + moco::tf::ShapeInferenceData shapedata; + loco_tobe::BiasShape dummy; + + shapedata.bias_shape(dummy); // this is to set domain to bias + + shapedata.rank(1); + shapedata.dim(0) = 3; + + loco_tobe::BiasShape bias = shapedata.bias_shape(); + + ASSERT_EQ(bias, 3); +}