From 2b7d800091fbc02561f2a321ac6f30d45e3ea23c Mon Sep 17 00:00:00 2001 From: DongHak Park Date: Fri, 14 Apr 2023 18:00:01 +0900 Subject: [PATCH] [TFLite Export] Update node_exporter Add Epsilon Props to additional_props for fusing - For Fusing we need Epsilon for batch norm Add padding, stride props to props_vector - For Conv Fusing we need to made new BuiltinOption and for building new BuiltinOption with FUSED activation we need padding,stride Signed-off-by: DongHak Park --- nntrainer/utils/node_exporter.cpp | 24 ++++++++++++++++++++++++ nntrainer/utils/node_exporter.h | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/nntrainer/utils/node_exporter.cpp b/nntrainer/utils/node_exporter.cpp index bc76ec4..a1b4a50 100644 --- a/nntrainer/utils/node_exporter.cpp +++ b/nntrainer/utils/node_exporter.cpp @@ -7,6 +7,7 @@ * @brief NNTrainer Node exporter * @see https://github.com/nnstreamer/nntrainer * @author Jihoon Lee + * @author Donghak Park * @bug No known bugs except for NYI items */ #include @@ -143,6 +144,24 @@ void Exporter::saveTflResult(const std::tuple &props, template <> void Exporter::saveTflResult( + const std::tuple &props, + const BatchNormalizationLayer *self) { + createIfNull(tf_node); + + auto epsilon = std::get(props).get(); + tf_node->AppendAdditionalProps(epsilon); + + tf_node->setOpType(tflite::BuiltinOperator_MUL); + auto options = + tflite::CreateMulOptions(*fbb, tflite::ActivationFunctionType_NONE).Union(); + tf_node->setBuiltinOptions(tflite::BuiltinOptions_MulOptions, options); +} + +template <> +void Exporter::saveTflResult( const std::tuple, std::array, props::Padding2D, std::array> &props, @@ -183,6 +202,11 @@ void Exporter::saveTflResult( auto options = tflite::CreateConv2DOptions(*fbb, tflite_padding(padding), strides.at(0), strides.at(1)) .Union(); + + tf_node->AppendProps(tflite_padding(padding)); + tf_node->AppendProps(strides.at(0)); + tf_node->AppendProps(strides.at(1)); + tf_node->setBuiltinOptions(tflite::BuiltinOptions_Conv2DOptions, options); } diff --git a/nntrainer/utils/node_exporter.h b/nntrainer/utils/node_exporter.h index e8220d9..dd7b8c6 100644 --- a/nntrainer/utils/node_exporter.h +++ b/nntrainer/utils/node_exporter.h @@ -7,6 +7,7 @@ * @brief NNTrainer Node exporter * @see https://github.com/nnstreamer/nntrainer * @author Jihoon Lee + * @author Donghak Park * @bug No known bugs except for NYI items */ #ifndef __NODE_EXPORTER_H__ @@ -22,6 +23,7 @@ #include #include #include +#include #include #include @@ -230,6 +232,7 @@ class InputConnection; class ClipGradByGlobalNorm; class DisableBias; class Activation; +class BatchNormalization; } // namespace props class LayerNode; @@ -245,6 +248,19 @@ void Exporter::saveTflResult( props::ClipGradByGlobalNorm> &props, const LayerNode *self); +class BatchNormalizationLayer; +/** + * @copydoc template void + * Exporter::saveTflResult(const PropsType &props, const NodeType *self); + */ +template <> +void Exporter::saveTflResult( + const std::tuple &props, + const BatchNormalizationLayer *self); + class LayerImpl; /** -- 2.7.4