From 8e32dbb9596565d4d02750b9851e32d8ffabba1c Mon Sep 17 00:00:00 2001 From: cjh9368 Date: Tue, 24 Nov 2020 10:43:32 +0800 Subject: [PATCH] tflite parser remove useless code and recitify registry --- .../parser/tflite/tflite_activation_parser.cc | 78 +-- .../parser/tflite/tflite_activation_parser.h | 4 - .../parser/tflite/tflite_addn_parser.cc | 36 +- .../parser/tflite/tflite_addn_parser.h | 4 - .../parser/tflite/tflite_argmax_parser.cc | 63 +-- .../parser/tflite/tflite_argmax_parser.h | 4 - .../parser/tflite/tflite_argmin_parser.cc | 63 +-- .../parser/tflite/tflite_argmin_parser.h | 9 +- .../parser/tflite/tflite_arithmetic_parser.cc | 447 ++---------------- .../parser/tflite/tflite_arithmetic_parser.h | 12 - .../tflite/tflite_batch_to_space_parser.cc | 61 +-- .../tflite/tflite_batch_to_space_parser.h | 9 +- .../tflite/tflite_broadcast_to_parser.cc | 43 +- .../tflite/tflite_broadcast_to_parser.h | 4 - .../parser/tflite/tflite_cast_parser.cc | 51 +- .../parser/tflite/tflite_cast_parser.h | 3 - .../parser/tflite/tflite_concat_parser.cc | 48 +- .../parser/tflite/tflite_concat_parser.h | 3 - .../parser/tflite/tflite_conv_parser.cc | 78 +-- .../parser/tflite/tflite_conv_parser.h | 3 - .../parser/tflite/tflite_custom_parser.cc | 66 +-- .../parser/tflite/tflite_custom_parser.h | 3 - .../parser/tflite/tflite_deconv_parser.cc | 84 +--- .../parser/tflite/tflite_deconv_parser.h | 9 +- .../tflite/tflite_depth_to_space_parser.cc | 41 +- .../tflite/tflite_depth_to_space_parser.h | 3 - .../tflite/tflite_depthwise_conv_parser.cc | 87 +--- .../tflite/tflite_depthwise_conv_parser.h | 4 - .../parser/tflite/tflite_dequantize_parser.cc | 58 +-- .../parser/tflite/tflite_dequantize_parser.h | 4 - .../tflite/tflite_expand_dims_parser.cc | 38 +- .../parser/tflite/tflite_expand_dims_parser.h | 3 - .../parser/tflite/tflite_fill_parser.cc | 39 +- .../parser/tflite/tflite_fill_parser.h | 4 - .../tflite/tflite_fullyconnected_parser.cc | 54 +-- .../tflite/tflite_fullyconnected_parser.h | 3 - .../parser/tflite/tflite_gather_nd_parser.cc | 36 +- .../parser/tflite/tflite_gather_nd_parser.h | 3 - .../parser/tflite/tflite_gather_parser.cc | 42 +- .../parser/tflite/tflite_gather_parser.h | 3 - .../tflite/tflite_hashtable_lookup_parser.cc | 38 +- .../tflite/tflite_hashtable_lookup_parser.h | 3 - .../parser/tflite/tflite_l2norm_parser.cc | 36 +- .../parser/tflite/tflite_l2norm_parser.h | 3 - .../parser/tflite/tflite_logical_parser.cc | 63 +-- .../parser/tflite/tflite_logical_parser.h | 3 - .../parser/tflite/tflite_lrn_parser.cc | 42 +- .../parser/tflite/tflite_lrn_parser.h | 3 - .../tflite/tflite_lsh_projection_parser.cc | 46 +- .../tflite/tflite_lsh_projection_parser.h | 3 - .../parser/tflite/tflite_matmul_parser.cc | 37 +- .../parser/tflite/tflite_matmul_parser.h | 11 +- .../parser/tflite/tflite_model_parser.cc | 6 +- .../parser/tflite/tflite_node_parser.h | 41 -- .../tflite/tflite_node_parser_registry.cc | 4 +- .../tflite/tflite_node_parser_registry.h | 8 +- .../parser/tflite/tflite_one_hot_parser.cc | 46 +- .../parser/tflite/tflite_one_hot_parser.h | 3 - .../parser/tflite/tflite_pad_parser.cc | 73 +-- .../parser/tflite/tflite_pad_parser.h | 3 - .../parser/tflite/tflite_pooling_parser.cc | 74 +-- .../parser/tflite/tflite_pooling_parser.h | 3 - .../parser/tflite/tflite_prelu_parser.cc | 33 +- .../parser/tflite/tflite_prelu_parser.h | 3 - .../parser/tflite/tflite_quantize_parser.cc | 57 +-- .../parser/tflite/tflite_quantize_parser.h | 3 - .../parser/tflite/tflite_range_parser.cc | 53 +-- .../parser/tflite/tflite_range_parser.h | 3 - .../parser/tflite/tflite_rank_parser.cc | 32 +- .../parser/tflite/tflite_rank_parser.h | 3 - .../parser/tflite/tflite_reduce_parser.cc | 76 +-- .../parser/tflite/tflite_reduce_parser.h | 3 - .../parser/tflite/tflite_reshape_parser.cc | 65 +-- .../parser/tflite/tflite_reshape_parser.h | 4 - .../parser/tflite/tflite_resize_parser.cc | 103 +--- .../parser/tflite/tflite_resize_parser.h | 3 - .../parser/tflite/tflite_reverse_parser.cc | 37 +- .../parser/tflite/tflite_reverse_parser.h | 3 - .../tflite/tflite_reverse_sequence_parser.cc | 44 +- .../tflite/tflite_reverse_sequence_parser.h | 3 - .../parser/tflite/tflite_scatter_nd_parser.cc | 40 +- .../parser/tflite/tflite_scatter_nd_parser.h | 3 - .../parser/tflite/tflite_shape_parser.cc | 32 +- .../parser/tflite/tflite_shape_parser.h | 3 - .../parser/tflite/tflite_skip_gram_parser.cc | 41 +- .../parser/tflite/tflite_skip_gram_parser.h | 3 - .../parser/tflite/tflite_slice_parser.cc | 48 +- .../parser/tflite/tflite_slice_parser.h | 3 - .../parser/tflite/tflite_softmax_parser.cc | 34 +- .../parser/tflite/tflite_softmax_parser.h | 4 - .../tflite/tflite_space_to_batch_nd_parser.cc | 44 +- .../tflite/tflite_space_to_batch_nd_parser.h | 3 - .../tflite/tflite_space_to_depth_parser.cc | 41 +- .../tflite/tflite_space_to_depth_parser.h | 3 - .../tflite/tflite_sparse_to_dense_parser.cc | 39 +- .../tflite/tflite_sparse_to_dense_parser.h | 3 - .../parser/tflite/tflite_split_parser.cc | 77 +-- .../parser/tflite/tflite_split_parser.h | 3 - .../parser/tflite/tflite_split_v_parser.cc | 72 +-- .../parser/tflite/tflite_split_v_parser.h | 3 - .../parser/tflite/tflite_squeeze_parser.cc | 39 +- .../parser/tflite/tflite_squeeze_parser.h | 3 - .../parser/tflite/tflite_stack_parser.cc | 44 +- .../parser/tflite/tflite_stack_parser.h | 3 - .../tflite/tflite_strided_slice_parser.cc | 66 +-- .../tflite/tflite_strided_slice_parser.h | 3 - .../parser/tflite/tflite_tile_parser.cc | 41 +- .../parser/tflite/tflite_tile_parser.h | 3 - .../parser/tflite/tflite_topk_v2_parser.cc | 42 +- .../parser/tflite/tflite_topk_v2_parser.h | 3 - .../parser/tflite/tflite_transpose_parser.cc | 39 +- .../parser/tflite/tflite_transpose_parser.h | 3 - .../parser/tflite/tflite_unique_parser.cc | 41 +- .../parser/tflite/tflite_unique_parser.h | 3 - .../parser/tflite/tflite_unstack_parser.cc | 42 +- .../parser/tflite/tflite_unstack_parser.h | 3 - .../parser/tflite/tflite_where_parser.cc | 39 +- .../parser/tflite/tflite_where_parser.h | 3 - .../parser/tflite/tflite_while_parser.cc | 44 +- .../parser/tflite/tflite_while_parser.h | 3 - .../parser/tflite/tflite_zeros_like_parser.cc | 33 +- .../parser/tflite/tflite_zeros_like_parser.h | 3 - 122 files changed, 156 insertions(+), 3530 deletions(-) diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc index 337fda4652..ce9825dd43 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc @@ -23,71 +23,6 @@ #include "tools/converter/parser/tflite/tflite_util.h" namespace mindspore::lite { -STATUS TfliteActivationParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "Relu") == 0) { - MS_LOG(DEBUG) << "parse TfliteReluParser"; - attr->type = schema::ActivationType_RELU; - } else if (std::strcmp(node_name, "Relu6") == 0) { - MS_LOG(DEBUG) << "parse TfliteRelu6Parser"; - attr->type = schema::ActivationType_RELU6; - } else if (std::strcmp(node_name, "Tanh") == 0) { - MS_LOG(DEBUG) << "parse TfliteTanhParser"; - attr->type = schema::ActivationType_TANH; - } else if (std::strcmp(node_name, "Logistic") == 0) { - MS_LOG(DEBUG) << "parse TfliteLogisticParser"; - attr->type = schema::ActivationType_SIGMOID; - } else if (std::strcmp(node_name, "Swish") == 0) { - MS_LOG(DEBUG) << "parse TfliteSwishParser"; - attr->type = schema::ActivationType_SWISH; - } else if (std::strcmp(node_name, "HardSwish") == 0) { - MS_LOG(DEBUG) << "parse TfliteHardSwishParser"; - attr->type = schema::ActivationType_HSWISH; - } else if (std::strcmp(node_name, "LeakyRelu") == 0) { - const auto &tflite_attr = tflite_op->builtin_options.AsLeakyReluOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->alpha = tflite_attr->alpha; - attr->type = schema::ActivationType_LEAKY_RELU; - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} - lite::PrimitiveC *TfliteActivationParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { std::unique_ptr attr = std::make_unique(); @@ -117,11 +52,10 @@ lite::PrimitiveC *TfliteActivationParser::ParseLitePrimitive(const std::unique_p return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_TfliteReluParser("ReLU", new TfliteActivationParser()); -TfliteNodeRegister g_TfliteRelu6Parser("ReLU6", new TfliteActivationParser()); -TfliteNodeRegister g_TfliteTanhParser("Tanh", new TfliteActivationParser()); -TfliteNodeRegister g_TfliteSwishParser("Swish", new TfliteActivationParser()); -TfliteNodeRegister g_TfliteHardSwishParser("HSwish", new TfliteActivationParser()); -TfliteNodeRegister g_tfliteLogisticParser("Logistic", new TfliteActivationParser()); -TfliteNodeRegister g_TfliteLeakyReluParser("LeakyRelu", new TfliteActivationParser()); +TfliteNodeRegister g_TfliteReluParser(tflite::BuiltinOperator_RELU, new TfliteActivationParser()); +TfliteNodeRegister g_TfliteRelu6Parser(tflite::BuiltinOperator_RELU6, new TfliteActivationParser()); +TfliteNodeRegister g_TfliteTanhParser(tflite::BuiltinOperator_TANH, new TfliteActivationParser()); +TfliteNodeRegister g_TfliteSwishParser(tflite::BuiltinOperator_HARD_SWISH, new TfliteActivationParser()); +TfliteNodeRegister g_tfliteLogisticParser(tflite::BuiltinOperator_LOGISTIC, new TfliteActivationParser()); +TfliteNodeRegister g_TfliteLeakyReluParser(tflite::BuiltinOperator_LEAKY_RELU, new TfliteActivationParser()); } // namespace mindspore::lite diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h index c39f1dbb0b..15977ab45b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h @@ -28,10 +28,6 @@ class TfliteActivationParser : public TfliteNodeParser { public: TfliteActivationParser() : TfliteNodeParser("node_name") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc index dcf38dbc01..6a7c6c1d0c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc @@ -22,40 +22,6 @@ #include "src/ops/addn.h" namespace mindspore::lite { -STATUS TfliteAddNParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteAddNParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->N = tflite_subgraph->tensors.size() - 1; - - op->primitive->value.type = schema::PrimitiveType_AddN; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} lite::PrimitiveC *TfliteAddNParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto attr = std::make_unique(); @@ -69,5 +35,5 @@ lite::PrimitiveC *TfliteAddNParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc index 223cfc0805..bd304270a9 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc @@ -19,63 +19,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteArgmaxParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteArgmaxParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->outMaxValue = false; - attr->topK = 1; - attr->keepDims = false; - attr->axisType = 1; - - // get axis attr - auto axis_idx = tflite_op->inputs[1]; - auto axis_tensor = tflite_subgraph->tensors[axis_idx].get(); - if (axis_tensor == nullptr) { - MS_LOG(ERROR) << "axis_tensor is null"; - return RET_NULL_PTR; - } - auto buffer_idx = axis_tensor->buffer; - auto &buf_data = tflite_model->buffers[buffer_idx]; - if (buf_data == nullptr) { - MS_LOG(ERROR) << "the buf data is null"; - return RET_NULL_PTR; - } - auto data_ptr = buf_data->data.data(); - if (data_ptr == nullptr) { - MS_LOG(ERROR) << "the data is null"; - return RET_NULL_PTR; - } - attr->axis = *(static_cast(static_cast(data_ptr))); - - op->primitive->value.type = schema::PrimitiveType_ArgMax; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteArgmaxParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { const auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -110,6 +54,5 @@ PrimitiveC *TfliteArgmaxParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc index 8374232050..1e4deebdb5 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc @@ -19,63 +19,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteArgminParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteArgminParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->outMaxValue = false; - attr->topK = 1; - attr->keepDims = false; - attr->axisType = 1; - - // get axis attr - auto axis_idx = tflite_op->inputs[1]; - auto axis_tensor = tflite_subgraph->tensors[axis_idx].get(); - if (axis_tensor == nullptr) { - MS_LOG(ERROR) << "axis_tensor is null"; - return RET_NULL_PTR; - } - auto buffer_idx = axis_tensor->buffer; - auto &buf_data = tflite_model->buffers[buffer_idx]; - if (buf_data == nullptr) { - MS_LOG(ERROR) << "the buf data is null"; - return RET_NULL_PTR; - } - auto data_ptr = buf_data->data.data(); - if (data_ptr == nullptr) { - MS_LOG(ERROR) << "the data is null"; - return RET_NULL_PTR; - } - attr->axis = *(static_cast(static_cast(data_ptr))); - - op->primitive->value.type = schema::PrimitiveType_ArgMin; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteArgminParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { const auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -110,6 +54,5 @@ PrimitiveC *TfliteArgminParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; -} // namespace lite -} // namespace mindspore +} // namespace mindspore::lite #endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_ARGMIN_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc index 2d138b6269..db6309b00b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc @@ -19,166 +19,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteDoubleInputOpParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "Add") == 0) { - MS_LOG(DEBUG) << "parse TfliteAddParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - const auto &tfliteAttr = tflite_op->builtin_options.AsAddOptions(); - if (nullptr == tfliteAttr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - op->primitive->value.type = schema::PrimitiveType_Add; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Sub") == 0) { - MS_LOG(DEBUG) << "parse TfliteSubParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - const auto &tfliteAttr = tflite_op->builtin_options.AsSubOptions(); - if (nullptr == tfliteAttr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - op->primitive->value.type = schema::PrimitiveType_Sub; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Mul") == 0) { - MS_LOG(DEBUG) << "parse TfliteMulParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - const auto &tfliteAttr = tflite_op->builtin_options.AsMulOptions(); - if (nullptr == tfliteAttr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - op->primitive->value.type = schema::PrimitiveType_Mul; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Div") == 0) { - MS_LOG(DEBUG) << "parse TfliteDivParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - const auto &tfliteAttr = tflite_op->builtin_options.AsDivOptions(); - if (nullptr == tfliteAttr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - op->primitive->value.type = schema::PrimitiveType_Div; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "FloorDiv") == 0) { - MS_LOG(DEBUG) << "parse TfliteFloorDivParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_FloorDiv; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "FloorMod") == 0) { - MS_LOG(DEBUG) << "parse TfliteFloorModParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_FloorMod; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "RealDiv") == 0) { - MS_LOG(DEBUG) << "parse TfliteRealDivParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Div; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "SquaredDifference") == 0) { - MS_LOG(DEBUG) << "parse TfliteSquaredDifferenceParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_SquaredDifference; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Pow") == 0) { - MS_LOG(DEBUG) << "parse TflitePowParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->power = 1.0f; - attr->scale = 1.0f; - attr->shift = 0.0f; - op->primitive->value.type = schema::PrimitiveType_Power; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Maximum") == 0) { - MS_LOG(DEBUG) << "parse TfliteMaximumParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Maximum; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Minimum") == 0) { - MS_LOG(DEBUG) << "parse TfliteMinimumParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Minimum; - op->primitive->value.value = attr.release(); - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - // set input - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteDoubleInputOpParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto tflite_op_type = (tflite_model->operator_codes[tflite_op->opcode_index])->builtin_code; @@ -307,146 +148,6 @@ PrimitiveC *TfliteDoubleInputOpParser::ParseLitePrimitive(const std::unique_ptr< return PrimitiveC::Create(primitive.release()); } -STATUS TfliteSingleInputOpParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "Abs") == 0) { - MS_LOG(DEBUG) << "parse TfliteAbsParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Abs; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Exp") == 0) { - MS_LOG(DEBUG) << "parse TfliteExpParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->base = -1; // -1 represent base = e - attr->scale = 1; - attr->shift = 0; - op->primitive->value.type = schema::PrimitiveType_Exp; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Sqrt") == 0) { - MS_LOG(DEBUG) << "parse TfliteSqrtParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Sqrt; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Rsqrt") == 0) { - MS_LOG(DEBUG) << "parse TfliteRsqrtParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Rsqrt; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Square") == 0) { - MS_LOG(DEBUG) << "parse TfliteSquareParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Square; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Sin") == 0) { - MS_LOG(DEBUG) << "parse TfliteSinParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Sin; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Cos") == 0) { - MS_LOG(DEBUG) << "parse TfliteCosParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Cos; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Log") == 0) { - MS_LOG(DEBUG) << "parse TfliteLogParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Log; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Round") == 0) { - MS_LOG(DEBUG) << "parse TfliteRoundParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Round; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Ceil") == 0) { - MS_LOG(DEBUG) << "parse TfliteCeilParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Ceil; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "flOOR") == 0) { - MS_LOG(DEBUG) << "parse TfliteFloorParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Floor; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Neg") == 0) { - MS_LOG(DEBUG) << "parse TfliteNegParser"; - auto attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Neg; - op->primitive->value.value = attr.release(); - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSingleInputOpParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto tflite_op_type = (tflite_model->operator_codes[tflite_op->opcode_index])->builtin_code; @@ -566,91 +267,6 @@ PrimitiveC *TfliteSingleInputOpParser::ParseLitePrimitive(const std::unique_ptr< return PrimitiveC::Create(primitive.release()); } -STATUS TfliteCompareOpParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "Equal") == 0) { - MS_LOG(DEBUG) << "parse TfliteEqualParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Equal; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "NotEqual") == 0) { - MS_LOG(DEBUG) << "parse TfliteNotEqualParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_NotEqual; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Greater") == 0) { - MS_LOG(DEBUG) << "parse TfliteGreaterParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Greater; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "GreaterEqual") == 0) { - MS_LOG(DEBUG) << "parse TfliteGreaterEqualParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_GreaterEqual; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "Less") == 0) { - MS_LOG(DEBUG) << "parse TfliteLessParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_Less; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "LessEqual") == 0) { - MS_LOG(DEBUG) << "parse TfliteLessEqualParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_LessEqual; - op->primitive->value.value = attr.release(); - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteCompareOpParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto tflite_op_type = (tflite_model->operator_codes[tflite_op->opcode_index])->builtin_code; @@ -714,36 +330,35 @@ PrimitiveC *TfliteCompareOpParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; @@ -41,10 +37,6 @@ class TfliteSingleInputOpParser : public TfliteNodeParser { public: TfliteSingleInputOpParser() : TfliteNodeParser("node_name") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; @@ -53,10 +45,6 @@ class TfliteCompareOpParser : public TfliteNodeParser { public: TfliteCompareOpParser() : TfliteNodeParser("node_name") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc index 1f2f1cc041..80526727e3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc @@ -21,59 +21,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteBatchToSpaceParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "BatchToSpace") == 0) { - MS_LOG(DEBUG) << "parse TfliteBatchToSpaceParser"; - } else if (std::strcmp(node_name, "BatchToSpaceND") == 0) { - MS_LOG(DEBUG) << "parse TfliteBatchToSpaceNDParser"; - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->blockShape)) { - MS_LOG(ERROR) << "get batchToSpace -> blockShape failed"; - return RET_ERROR; - } - if (GetTfliteData(tflite_op->inputs[2], tflite_subgraph->tensors, tflite_model->buffers, attr->crops)) { - MS_LOG(ERROR) << "get batchToSpace -> crops failed"; - return RET_ERROR; - } - - op->primitive->value.type = schema::PrimitiveType_BatchToSpace; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteBatchToSpaceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { const auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -98,7 +46,6 @@ PrimitiveC *TfliteBatchToSpaceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; -} // namespace lite -} // namespace mindspore +} // namespace mindspore::lite #endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_BATCH_TO_SPACE_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc index 02b29d1eda..c7a1769941 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc @@ -19,44 +19,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteBroadcastToParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteBroadcastToParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->dst_shape)) { - MS_LOG(ERROR) << "get broadCastTo -> dst_shape failed"; - return RET_ERROR; - } - - op->primitive->value.type = schema::PrimitiveType_BroadcastTo; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteBroadcastToParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -80,6 +43,4 @@ PrimitiveC *TfliteBroadcastToParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc index 28d630ad94..ee3dd1804a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc @@ -18,51 +18,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteCastParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteCastParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &in_tensor = tflite_subgraph->tensors[tflite_op->inputs[0]]; - if (in_tensor == nullptr) { - MS_LOG(ERROR) << "tensor is null"; - return RET_NULL_PTR; - } - attr->srcT = GetTfliteDataType(in_tensor->type); - const auto &out_tensor = tflite_subgraph->tensors[tflite_op->outputs[0]]; - if (out_tensor == nullptr) { - MS_LOG(ERROR) << "tensor is null"; - return RET_NULL_PTR; - } - attr->dstT = GetTfliteDataType(out_tensor->type); - - op->primitive->value.type = schema::PrimitiveType_Cast; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteCastParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -90,6 +46,5 @@ PrimitiveC *TfliteCastParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc index 9a3b51ca49..8f290bf184 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc @@ -18,48 +18,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteConcatParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteConcatParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tfliteAttr = tflite_op->builtin_options.AsConcatenationOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->axis = tfliteAttr->axis; - attr->n = tflite_op->inputs.size(); - - op->primitive->value.type = schema::PrimitiveType_Concat; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteConcatParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -81,6 +40,5 @@ PrimitiveC *TfliteConcatParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc index 1fec27f723..74f2fe8b8f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc @@ -19,82 +19,6 @@ #include namespace mindspore::lite { -STATUS TfliteConvParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteConvParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsConv2DOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->group = 1; - attr->strideW = tflite_attr->stride_w; - attr->strideH = tflite_attr->stride_h; - attr->dilateH = tflite_attr->dilation_h_factor; - attr->dilateW = tflite_attr->dilation_w_factor; - attr->padMode = GetPadMode(tflite_attr->padding); - attr->format = schema::Format::Format_NHWC; - attr->activationType = GetActivationFunctionType(tflite_attr->fused_activation_function); - attr->hasBias = true; - - // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_subgraph->tensors[weight_index]; - if (weight_tensor == nullptr) { - MS_LOG(ERROR) << "the weight tensor is null"; - return RET_NULL_PTR; - } - auto weight_shape = weight_tensor->shape; - attr->channelIn = weight_shape[3]; - attr->channelOut = weight_shape[0]; - attr->kernelH = weight_shape[1]; - attr->kernelW = weight_shape[2]; - - // calculate pad params - auto data_index = tflite_op->inputs[0]; - const auto &data_tensor = tflite_subgraph->tensors[data_index]; - std::vector params; - int status = - getPaddingParam(data_tensor, attr->padMode, attr->strideH, attr->strideW, attr->kernelH, attr->kernelW, ¶ms); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "get padding params failed"; - return RET_ERROR; - } else if (status == RET_OK) { - attr->padUp = params.at(0); - attr->padDown = params.at(1); - attr->padLeft = params.at(2); - attr->padRight = params.at(3); - } - - op->primitive->value.type = schema::PrimitiveType_Conv2D; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_KHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[2], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} lite::PrimitiveC *TfliteConvParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { const auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -153,5 +77,5 @@ lite::PrimitiveC *TfliteConvParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_custom_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_custom_parser.cc index 60aed771a7..b57ad24cbf 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_custom_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_custom_parser.cc @@ -207,70 +207,6 @@ STATUS TfliteCustomParser::BatchMatMul(const std::vector &custom_attr, return RET_OK; } -STATUS TfliteCustomParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteCustomParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - const auto &custom_attr = tflite_op->custom_options; - const auto opcode_index = tflite_op->opcode_index; - const auto &operator_code = tflite_model->operator_codes[opcode_index]; - if (operator_code == nullptr) { - MS_LOG(ERROR) << "operator_code is null"; - return RET_NULL_PTR; - } - const auto &custom_type = operator_code->custom_code; - - int status = RET_OK; - if (custom_type == "TFLite_Detection_PostProcess") { - status = DetectPostProcess(custom_attr, op, tflite_op); - } else if (custom_type == "Predict") { - status = Predict(custom_attr, op, tflite_op); - } else if (custom_type == "Normalize") { - status = Normalize(custom_attr, op, tflite_op); - } else if (custom_type == "ExtractFeatures") { - status = ExtractFeatures(custom_attr, op, tflite_op); - } else if (custom_type == "AudioSpectrogram") { - status = AudioSpectrogram(custom_attr, op, tflite_op); - } else if (custom_type == "Mfcc") { - status = Mfcc(custom_attr, op, tflite_op); - } else if (custom_type == "FlexRFFT") { - status = Rfft(custom_attr, op, tflite_op, tflite_model, tflite_subgraph); - } else if (custom_type == "FlexReal") { - status = FftReal(custom_attr, op, tflite_op); - } else if (custom_type == "FlexImag") { - status = FftImag(custom_attr, op, tflite_op); - } else if (custom_type == "FlexIdentityN" || custom_type == "FlexIdentity") { - status = Identity(custom_attr, op, tflite_op); - } else if (custom_type == "FlexBatchMatMul") { - status = BatchMatMul(custom_attr, op, tflite_op); - } else { - MS_LOG(ERROR) << "the custom op hasn't been supported now"; - status = RET_NOT_FIND_OP; - } - if (status != RET_OK) { - return status; - } - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return status; -} PrimitiveC *TfliteCustomParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -314,6 +250,6 @@ PrimitiveC *TfliteCustomParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc index 66be277d76..74df4db85e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc @@ -18,84 +18,7 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteDeConvParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse tflite Transpose_Conv parser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsTransposeConvOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - - attr->group = 1; - attr->strideW = tflite_attr->stride_w; - attr->strideH = tflite_attr->stride_h; - attr->dilateH = 1; - attr->dilateW = 1; - attr->padMode = GetPadMode(tflite_attr->padding); - attr->format = schema::Format::Format_NHWC; - attr->activationType = schema::ActivationType_NO_ACTIVATION; - attr->hasBias = true; - - // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_subgraph->tensors[weight_index]; - if (weight_tensor == nullptr) { - MS_LOG(ERROR) << "the weight tensor is null"; - return RET_NULL_PTR; - } - auto weight_shape = weight_tensor->shape; - attr->channelIn = weight_shape[3]; - attr->channelOut = weight_shape[0]; - attr->kernelH = weight_shape[1]; - attr->kernelW = weight_shape[2]; - - // calculate pad params - auto data_index = tflite_op->inputs[2]; - const auto &data_tensor = tflite_subgraph->tensors[data_index]; - std::vector params; - int status = - getPaddingParam(data_tensor, attr->padMode, attr->strideH, attr->strideW, attr->kernelH, attr->kernelW, ¶ms); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "get padding params failed"; - return RET_ERROR; - } else if (status == RET_OK) { - attr->padUp = params.at(0); - attr->padDown = params.at(1); - attr->padLeft = params.at(2); - attr->padRight = params.at(3); - } - - op->primitive->value.type = schema::PrimitiveType_DeConv2D; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[2], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_KHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} +namespace mindspore::lite { PrimitiveC *TfliteDeConvParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -155,6 +78,5 @@ PrimitiveC *TfliteDeConvParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; -} // namespace lite -} // namespace mindspore +} // namespace mindspore::lite #endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_DECONV_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc index 4767c62225..c8854a64f1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc @@ -21,45 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteDepthToSpaceParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteDepthToSpaceParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsDepthToSpaceOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); - return RET_NULL_PTR; - } - attr->blockSize = tflite_attr->block_size; - attr->format = schema::Format::Format_NHWC; - - op->primitive->value.type = schema::PrimitiveType_DepthToSpace; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteDepthToSpaceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { std::unique_ptr attr = std::make_unique(); @@ -81,6 +42,6 @@ PrimitiveC *TfliteDepthToSpaceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc index d733b8aeec..a585236500 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc @@ -19,90 +19,6 @@ #include namespace mindspore::lite { -STATUS TfliteDepthwiseConv2DParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, - schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteDepthwiseConv2DParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsDepthwiseConv2DOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->strideW = tflite_attr->stride_w; - attr->strideH = tflite_attr->stride_h; - attr->dilateH = tflite_attr->dilation_h_factor; - attr->dilateW = tflite_attr->dilation_w_factor; - attr->padMode = GetPadMode(tflite_attr->padding); - attr->format = schema::Format::Format_NHWC; - attr->activationType = GetActivationFunctionType(tflite_attr->fused_activation_function); - attr->hasBias = true; - attr->channelMultiplier = tflite_attr->depth_multiplier; - - // get the data tensor - auto data_index = tflite_op->inputs[1]; - const auto &data_tensor = tflite_subgraph->tensors[data_index]; - if (data_tensor == nullptr) { - MS_LOG(ERROR) << "the data tensor is null"; - return RET_NULL_PTR; - } - auto data_shape = data_tensor->shape; - attr->channelIn = data_shape[3]; - - // get the weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_subgraph->tensors[weight_index]; - if (weight_tensor == nullptr) { - MS_LOG(ERROR) << "the weight tensor is null"; - return RET_NULL_PTR; - } - auto weight_shape = weight_tensor->shape; - attr->kernelH = weight_shape[1]; - attr->kernelW = weight_shape[2]; - - // calculate pad params - std::vector params; - int status = - getPaddingParam(data_tensor, attr->padMode, attr->strideH, attr->strideW, attr->kernelH, attr->kernelW, ¶ms); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "get padding params failed"; - return RET_ERROR; - } else if (status == RET_OK) { - attr->padUp = params.at(0); - attr->padDown = params.at(1); - attr->padLeft = params.at(2); - attr->padRight = params.at(3); - } - - op->primitive->value.type = schema::PrimitiveType_DepthwiseConv2D; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_KHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[2], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} lite::PrimitiveC *TfliteDepthwiseConv2DParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { MS_LOG(DEBUG) << "parse TfliteDepthwiseConv2DParser"; @@ -169,5 +85,6 @@ lite::PrimitiveC *TfliteDepthwiseConv2DParser::ParseLitePrimitive(const std::uni return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteDepthwiseConv2DParser("DepthwiseConv2D", new TfliteDepthwiseConv2DParser()); +TfliteNodeRegister g_tfliteDepthwiseConv2DParser(tflite::BuiltinOperator_DEPTHWISE_CONV_2D, + new TfliteDepthwiseConv2DParser()); } // namespace mindspore::lite diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.h index 1357ed5b97..fda28855d3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.h @@ -28,10 +28,6 @@ class TfliteDepthwiseConv2DParser : public TfliteNodeParser { public: TfliteDepthwiseConv2DParser() : TfliteNodeParser("DepthwiseConv2D") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_dequantize_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_dequantize_parser.cc index bdca34405f..44465ddb5c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_dequantize_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_dequantize_parser.cc @@ -19,62 +19,6 @@ namespace mindspore { namespace lite { -STATUS TfliteDequantizeParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteDequantizeNParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - const auto &in_tensor = tflite_subgraph->tensors[tflite_op->inputs[0]]; - if (in_tensor == nullptr) { - MS_LOG(ERROR) << "input tensor is null"; - return RET_NULL_PTR; - } - const auto &out_tensor = tflite_subgraph->tensors[tflite_op->outputs[0]]; - if (out_tensor == nullptr) { - MS_LOG(ERROR) << "output tensor is null"; - return RET_NULL_PTR; - } - if (GetTfliteDataType(in_tensor->type) != GetTfliteDataType(out_tensor->type) && - (GetTfliteDataType(in_tensor->type) == kNumberTypeInt8 || - GetTfliteDataType(in_tensor->type) == kNumberTypeUInt8)) { - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->srcT = GetTfliteDataType(in_tensor->type); - attr->dstT = GetTfliteDataType(out_tensor->type); - op->primitive->value.value = attr.release(); - op->primitive->value.type = schema::PrimitiveType_QuantDTypeCast; - } else { - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->srcT = GetTfliteDataType(in_tensor->type); - attr->dstT = GetTfliteDataType(out_tensor->type); - op->primitive->value.value = attr.release(); - op->primitive->value.type = schema::PrimitiveType_Cast; - } - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteDequantizeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -115,6 +59,6 @@ PrimitiveC *TfliteDequantizeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc index adcab9769d..bbf5139744 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc @@ -20,42 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteExpandDimsParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteExpandDimsParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - std::vector dims; - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, dims)) { - MS_LOG(ERROR) << "get expand_dims -> dim failed"; - return RET_ERROR; - } - attr->dim = dims[0]; - op->primitive->value.type = schema::PrimitiveType_ExpandDims; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteExpandDimsParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -80,6 +44,6 @@ PrimitiveC *TfliteExpandDimsParser::ParseLitePrimitive(const std::unique_ptrvalue.value = attr.release(); return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteExpandDimsParser("ExpandDims", new TfliteExpandDimsParser()); +TfliteNodeRegister g_tfliteExpandDimsParser(tflite::BuiltinOperator_EXPAND_DIMS, new TfliteExpandDimsParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.h index 7169bb8c6c..4c4be4891c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.h @@ -29,9 +29,6 @@ class TfliteExpandDimsParser : public TfliteNodeParser { public: TfliteExpandDimsParser() : TfliteNodeParser("ExpandDims") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc index 1aa64ca07f..ee1195a6c7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc @@ -20,43 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteFillParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteFillParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (tflite_op->inputs.size() > 1) { - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->dims)) { - MS_LOG(ERROR) << "get fill -> dims failed"; - return RET_ERROR; - } - } - - op->primitive->value.type = schema::PrimitiveType_Fill; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteFillParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -84,6 +47,6 @@ PrimitiveC *TfliteFillParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc index ebca042418..cb1099a33a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc @@ -20,55 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteFullyConnectedParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, - schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteFullyConnectedParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsFullyConnectedOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - - bool hasBias = tflite_op->inputs.size() > 2 && tflite_op->inputs[2] != -1; - - attr->hasBias = hasBias; - attr->axis = 1; - attr->useAxis = false; - attr->activationType = GetActivationFunctionType(tflite_attr->fused_activation_function); - - op->primitive->value.type = schema::PrimitiveType_FullConnection; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_KHWC); - if (hasBias) { - AddOpInput(op, tensors_info, tflite_op->inputs[2], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteFullyConnectedParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -101,7 +52,8 @@ PrimitiveC *TfliteFullyConnectedParser::ParseLitePrimitive(const std::unique_ptr return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteFullyConnectedParser("FullyConnected", new TfliteFullyConnectedParser()); -TfliteNodeRegister g_tfliteFakeQuantParser("FakeQuant", new TfliteFullyConnectedParser()); +TfliteNodeRegister g_tfliteFullyConnectedParser(tflite::BuiltinOperator_FULLY_CONNECTED, + new TfliteFullyConnectedParser()); +TfliteNodeRegister g_tfliteFakeQuantParser(tflite::BuiltinOperator_FAKE_QUANT, new TfliteFullyConnectedParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.h index af8caa994c..1150a29a4e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.h @@ -29,9 +29,6 @@ class TfliteFullyConnectedParser : public TfliteNodeParser { public: TfliteFullyConnectedParser() : TfliteNodeParser("FullyConnected") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc index ab1ada4aa7..7188ead844 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc @@ -20,40 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteGatherNdParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteGatherNdParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->batchDims = 0; - - op->primitive->value.type = schema::PrimitiveType_GatherNd; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteGatherNdParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -75,6 +41,6 @@ PrimitiveC *TfliteGatherNdParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc index a55bce231e..9aaf91d533 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc @@ -20,46 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteGatherParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteGatherParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsGatherOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->axis = tflite_attr->axis; - attr->batchDims = 0; - - op->primitive->value.type = schema::PrimitiveType_Gather; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteGatherParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -87,6 +47,6 @@ PrimitiveC *TfliteGatherParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.cc index a98a7dae88..0b96b0a276 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.cc @@ -20,41 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteHashtableLookupParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, - schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteHashtableLookupParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - op->primitive->value.type = schema::PrimitiveType_HashtableLookup; - op->primitive->value.value = attr.release(); - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteHashtableLookupParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -74,6 +39,7 @@ PrimitiveC *TfliteHashtableLookupParser::ParseLitePrimitive(const std::unique_pt return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteHashtableLookupParser("HashtableLookup", new TfliteHashtableLookupParser()); +TfliteNodeRegister g_tfliteHashtableLookupParser(tflite::BuiltinOperator_HASHTABLE_LOOKUP, + new TfliteHashtableLookupParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.h index 1af5fd118c..fc24430806 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_hashtable_lookup_parser.h @@ -29,9 +29,6 @@ class TfliteHashtableLookupParser : public TfliteNodeParser { public: TfliteHashtableLookupParser() : TfliteNodeParser("HashtableLookup") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_l2norm_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_l2norm_parser.cc index b9ff61a67c..b7e3aaf8bd 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_l2norm_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_l2norm_parser.cc @@ -21,40 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteL2NormParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteL2NormParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - const auto &tflite_attr = tflite_op->builtin_options.AsL2NormOptions(); - attr->axis = {-1}; - attr->epsilon = 1e-6f; - attr->activationType = GetActivationFunctionType(tflite_attr->fused_activation_function); - - op->primitive->value.type = schema::PrimitiveType_L2Norm; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteL2NormParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { std::unique_ptr attr = std::make_unique(); @@ -77,6 +43,6 @@ PrimitiveC *TfliteL2NormParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc index 3009a9d7fe..f65cdc093b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc @@ -21,63 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteLogicalParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "LogicalAnd") == 0) { - MS_LOG(DEBUG) << "parse TfliteLogicalAndParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_LogicalAnd; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "LogicalNot") == 0) { - MS_LOG(DEBUG) << "parse TfliteLogicalNotParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_LogicalNot; - op->primitive->value.value = attr.release(); - } else if (std::strcmp(node_name, "LogicalOr") == 0) { - MS_LOG(DEBUG) << "parse TfliteLogicalOrParser"; - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_LogicalOr; - op->primitive->value.value = attr.release(); - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteLogicalParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -117,8 +60,8 @@ PrimitiveC *TfliteLogicalParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc index 82d63c30dd..af6f2c2558 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc @@ -20,46 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteLRNParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteLRNParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsLocalResponseNormalizationOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->depth_radius = tflite_attr->radius; - attr->alpha = tflite_attr->alpha; - attr->beta = tflite_attr->beta; - attr->bias = tflite_attr->bias; - - op->primitive->value.type = schema::PrimitiveType_LocalResponseNormalization; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteLRNParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -89,6 +49,6 @@ PrimitiveC *TfliteLRNParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.cc index 103d1a94f2..e66fa261f7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.cc @@ -20,50 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteLshProjectionParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteLshProjectionParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsLSHProjectionOptions(); - switch (tflite_attr->type) { - case tflite::LSHProjectionType_SPARSE: - attr->type = schema::LshProjectionType_SPARSE; - break; - case tflite::LSHProjectionType_DENSE: - attr->type = schema::LshProjectionType_DENSE; - break; - default: - attr->type = schema::LshProjectionType_UNKNOWN; - } - op->primitive->value.type = schema::PrimitiveType_LshProjection; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteLshProjectionParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -94,6 +50,6 @@ PrimitiveC *TfliteLshProjectionParser::ParseLitePrimitive(const std::unique_ptr< return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteLshProjectionParser("LshProjection", new TfliteLshProjectionParser()); +TfliteNodeRegister g_tfliteLshProjectionParser(tflite::BuiltinOperator_LSH_PROJECTION, new TfliteLshProjectionParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.h index 359ea23002..f3759d6ef6 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_lsh_projection_parser.h @@ -29,9 +29,6 @@ class TfliteLshProjectionParser : public TfliteNodeParser { public: TfliteLshProjectionParser() : TfliteNodeParser("LshProjection") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.cc index 3eaaa702b1..61af580b70 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.cc @@ -19,41 +19,28 @@ #include #include -namespace mindspore { -namespace lite { -STATUS TfliteMatMulParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteMatMulParser"; - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; +namespace mindspore::lite { +PrimitiveC *TfliteMatMulParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, + const std::unique_ptr &tflite_model) { + auto primitive = std::make_unique(); + if (primitive == nullptr) { + MS_LOG(ERROR) << "primitive is null"; + return nullptr; } std::unique_ptr attr = std::make_unique(); if (attr == nullptr) { MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; + return nullptr; } const auto &tflite_attr = tflite_op->builtin_options.AsBatchMatMulOptions(); attr->transposeA = tflite_attr->adj_x; attr->transposeB = tflite_attr->adj_y; attr->broadcast = false; - op->primitive->value.type = schema::PrimitiveType_MatMul; - op->primitive->value.value = attr.release(); + primitive->value.type = schema::PrimitiveType_MatMul; + primitive->value.value = attr.release(); - for (size_t i = 0; i < tflite_op->inputs.size(); i++) { - AddOpInput(op, tensors_info, tflite_op->inputs[i], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; + return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteMatMulParser("MatMul", new TfliteMatMulParser()); -} // namespace lite -} // namespace mindspore +} // namespace mindspore::lite diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.h index 1f02bf4b9f..d23c8a429d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_matmul_parser.h @@ -23,17 +23,14 @@ #include "tools/converter/parser/tflite/tflite_node_parser.h" #include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -namespace mindspore { -namespace lite { +namespace mindspore::lite { class TfliteMatMulParser : public TfliteNodeParser { public: TfliteMatMulParser() : TfliteNodeParser("MatMul") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; + PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, + const std::unique_ptr &tflite_model) override; }; -} // namespace lite -} // namespace mindspore +} // namespace mindspore::lite #endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_SLICE_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc index b9ed34bad0..3f548dd92e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc @@ -86,12 +86,12 @@ STATUS TfliteModelParser::ConvertOps() { STATUS status = RET_OK; int op_idx = 0; for (auto &op : tflite_subgraph->operators) { - auto tfliteOpType = (tflite_model_->operator_codes[op->opcode_index])->builtin_code; - auto op_type = GetMSOpType(tfliteOpType); + auto tflite_op_type = (tflite_model_->operator_codes[op->opcode_index])->builtin_code; + auto op_type = GetMSOpType(tflite_op_type); auto op_name = op_type + "-" + std::to_string(op_idx); op_idx++; // parse primitive - auto node_parser = TfliteNodeParserRegistry::GetInstance()->GetNodeParser(op_type); + auto node_parser = TfliteNodeParserRegistry::GetInstance()->GetNodeParser(tflite_op_type); if (node_parser == nullptr) { NoSupportOp::GetInstance()->InsertOp(op_type); status = (status == RET_OK ? RET_NOT_FIND_OP : status); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h index 4fa0698f36..3691cdbe5e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h @@ -38,52 +38,11 @@ class TfliteNodeParser { virtual ~TfliteNodeParser() = default; - virtual STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) = 0; virtual lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { return nullptr; } - static void AddOpInput(schema::CNodeT *op, TfliteTensorsInfo *tensors_info, int idx, int total, - schema::Format format) { - MS_ASSERT(op != nullptr); - MS_ASSERT(tensors_info != nullptr); - int new_idx = tensors_info->tensorsId.size(); - auto iter = tensors_info->tensorsIdMap.find(idx); - if (iter != tensors_info->tensorsIdMap.end()) { - op->inputIndex.emplace_back(iter->second); - } else { - if (idx < 0) { - idx += total; - } - tensors_info->tensorsId.emplace_back(idx); - tensors_info->tensorsFormat.emplace_back(format); - tensors_info->tensorsIdMap.insert(std::make_pair(idx, new_idx)); - op->inputIndex.emplace_back(new_idx); - } - } - - static void AddOpOutput(schema::CNodeT *op, TfliteTensorsInfo *tensors_info, int idx, int total, - schema::Format format) { - MS_ASSERT(op != nullptr); - MS_ASSERT(tensors_info != nullptr); - int new_idx = tensors_info->tensorsId.size(); - auto iter = tensors_info->tensorsIdMap.find(idx); - if (iter != tensors_info->tensorsIdMap.end()) { - op->outputIndex.emplace_back(iter->second); - } else { - if (idx < 0) { - idx += total; - } - tensors_info->tensorsId.emplace_back(idx); - tensors_info->tensorsFormat.emplace_back(format); - tensors_info->tensorsIdMap.insert(std::make_pair(idx, new_idx)); - op->outputIndex.emplace_back(new_idx); - } - } - template STATUS GetTfliteData(const int32_t tensor_index, const std::vector> &tflite_tensors, const std::vector> &tflite_model_buffer, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.cc index b420b99927..01452607e2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.cc @@ -34,8 +34,8 @@ TfliteNodeParserRegistry *TfliteNodeParserRegistry::GetInstance() { return &instance; } -TfliteNodeParser *TfliteNodeParserRegistry::GetNodeParser(const std::string &name) { - auto it = parsers.find(name); +TfliteNodeParser *TfliteNodeParserRegistry::GetNodeParser(const tflite::BuiltinOperator &type) { + auto it = parsers.find(type); if (it != parsers.end()) { return it->second; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h index 214a9460ed..9332ad94c3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h @@ -31,15 +31,15 @@ class TfliteNodeParserRegistry { static TfliteNodeParserRegistry *GetInstance(); - TfliteNodeParser *GetNodeParser(const std::string &name); + TfliteNodeParser *GetNodeParser(const tflite::BuiltinOperator &type); - std::unordered_map parsers; + std::unordered_map parsers; }; class TfliteNodeRegister { public: - TfliteNodeRegister(const std::string &name, TfliteNodeParser *parser) { - TfliteNodeParserRegistry::GetInstance()->parsers[name] = parser; + TfliteNodeRegister(const tflite::BuiltinOperator &type, TfliteNodeParser *parser) { + TfliteNodeParserRegistry::GetInstance()->parsers[type] = parser; } }; } // namespace lite diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc index 16b6cf7348..f3f08eb329 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc @@ -20,50 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteOneHotParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteOneHotParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsOneHotOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->axis = tflite_attr->axis; - - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_OneHot; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteOneHotParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -97,6 +53,6 @@ PrimitiveC *TfliteOneHotParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc index 231843174f..68b9ced562 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc @@ -21,75 +21,6 @@ namespace mindspore { namespace lite { -STATUS TflitePadParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TflitePadParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "Pad") == 0) { - const auto &tflite_attr = tflite_op->builtin_options.AsPadOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->paddingMode = schema::PaddingMode_CONSTANT; - attr->constantValue = 0.0f; - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->paddings)) { - MS_LOG(ERROR) << "get pad -> paddings failed"; - return RET_ERROR; - } - } else if (std::strcmp(node_name, "MirrorPad") == 0) { - const auto &tflite_attr = tflite_op->builtin_options.AsMirrorPadOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - switch (tflite_attr->mode) { - case tflite::MirrorPadMode_REFLECT: - attr->paddingMode = schema::PaddingMode_REFLECT; - break; - case tflite::MirrorPadMode_SYMMETRIC: - attr->paddingMode = schema::PaddingMode_SYMMETRIC; - break; - default: - MS_LOG(ERROR) << "paddingmode:" << tflite_attr->mode << " don't support"; - return RET_NOT_SUPPORT; - } - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - op->primitive->value.type = schema::PrimitiveType_Pad; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - if (std::strcmp(node_name, "MirrorPad") == 0) { - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TflitePadParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -144,7 +75,7 @@ PrimitiveC *TflitePadParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc index 9dd2843655..1bdc80acb2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc @@ -20,76 +20,6 @@ #include namespace mindspore::lite { -STATUS TflitePoolingParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - auto tflite_op_type = (tflite_model->operator_codes[tflite_op->opcode_index])->builtin_code; - if (tflite_op_type == tflite::BuiltinOperator_AVERAGE_POOL_2D) { - attr->poolingMode = schema::PoolMode_MEAN_POOLING; - } else if (tflite_op_type == tflite::BuiltinOperator_MAX_POOL_2D) { - attr->poolingMode = schema::PoolMode_MAX_POOLING; - } else { - MS_LOG(ERROR) << "pooling mode " << tflite_op_type << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsPool2DOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->windowW = tflite_attr->filter_width; - attr->windowH = tflite_attr->filter_height; - attr->strideW = tflite_attr->stride_w; - attr->strideH = tflite_attr->stride_h; - attr->padMode = GetPadMode(tflite_attr->padding); - attr->format = schema::Format::Format_NHWC; - attr->global = false; - attr->roundMode = schema::RoundMode_FLOOR; - attr->activationType = GetActivationFunctionType(tflite_attr->fused_activation_function); - - // calculate pad params - auto data_index = tflite_op->inputs[0]; - const auto &data_tensor = tflite_subgraph->tensors[data_index]; - std::vector params; - int status = - getPaddingParam(data_tensor, attr->padMode, attr->strideH, attr->strideW, attr->windowH, attr->windowW, ¶ms); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "get padding params failed"; - return RET_ERROR; - } else if (status == RET_OK) { - attr->padUp = params.at(0); - attr->padDown = params.at(1); - attr->padLeft = params.at(2); - attr->padRight = params.at(3); - } - - op->primitive->value.type = schema::PrimitiveType_Pooling; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} lite::PrimitiveC *TflitePoolingParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { const auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -142,6 +72,6 @@ lite::PrimitiveC *TflitePoolingParser::ParseLitePrimitive(const std::unique_ptr< return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteMeanPoolingParser("MeanPooling", new TflitePoolingParser()); -TfliteNodeRegister g_tfliteMaxPoolingParser("MaxPooling", new TflitePoolingParser()); +TfliteNodeRegister g_tfliteMeanPoolingParser(tflite::BuiltinOperator_AVERAGE_POOL_2D, new TflitePoolingParser()); +TfliteNodeRegister g_tfliteMaxPoolingParser(tflite::BuiltinOperator_MAX_POOL_2D, new TflitePoolingParser()); } // namespace mindspore::lite diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h index 48ec978ef3..58d2c1869a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h @@ -28,9 +28,6 @@ class TflitePoolingParser : public TfliteNodeParser { public: TflitePoolingParser() : TfliteNodeParser("node_name") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_prelu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_prelu_parser.cc index 42c49aa7e8..ce4ebc61fa 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_prelu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_prelu_parser.cc @@ -21,37 +21,6 @@ namespace mindspore { namespace lite { -STATUS TflitePReLUParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TflitePReLUParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->channelShared = true; - op->primitive->value.type = schema::PrimitiveType_PReLU; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TflitePReLUParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -71,6 +40,6 @@ PrimitiveC *TflitePReLUParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_quantize_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_quantize_parser.cc index 7688b55cfc..0c61348cba 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_quantize_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_quantize_parser.cc @@ -19,61 +19,6 @@ namespace mindspore { namespace lite { -STATUS TfliteQuantizeParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteQuantizeNParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - const auto &in_tensor = tflite_subgraph->tensors[tflite_op->inputs[0]]; - if (in_tensor == nullptr) { - MS_LOG(ERROR) << "input tensor is null"; - return RET_NULL_PTR; - } - const auto &out_tensor = tflite_subgraph->tensors[tflite_op->outputs[0]]; - if (out_tensor == nullptr) { - MS_LOG(ERROR) << "output tensor is null"; - return RET_NULL_PTR; - } - if (GetTfliteDataType(in_tensor->type) != GetTfliteDataType(out_tensor->type) && - (GetTfliteDataType(out_tensor->type) == kNumberTypeInt8 || - GetTfliteDataType(out_tensor->type) == kNumberTypeUInt8)) { - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->srcT = GetTfliteDataType(in_tensor->type); - attr->dstT = GetTfliteDataType(out_tensor->type); - op->primitive->value.type = schema::PrimitiveType_QuantDTypeCast; - op->primitive->value.value = attr.release(); - } else { - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->srcT = GetTfliteDataType(in_tensor->type); - attr->dstT = GetTfliteDataType(out_tensor->type); - op->primitive->value.type = schema::PrimitiveType_Cast; - op->primitive->value.value = attr.release(); - } - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteQuantizeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -119,6 +64,6 @@ PrimitiveC *TfliteQuantizeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc index 9dda4059e2..34d3221550 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc @@ -20,57 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteRangeParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteRangeParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->dType = 0; - std::vector limit; - std::vector delta; - int status = GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, limit); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "range -> limit get failed"; - return RET_ERROR; - } else if (status == RET_OK) { - status = GetTfliteData(tflite_op->inputs[2], tflite_subgraph->tensors, tflite_model->buffers, delta); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "stridedSlice -> end get failed"; - return RET_ERROR; - } - } - if (status == RET_OK) { - attr->limit = limit.front(); - attr->delta = delta.front(); - } - op->primitive->value.type = schema::PrimitiveType_Range; - op->primitive->value.value = attr.release(); - - int input_num = status == RET_OK ? 1 : 3; - for (int i = 0; i < input_num; ++i) { - AddOpInput(op, tensors_info, tflite_op->inputs[i], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteRangeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -109,6 +58,6 @@ PrimitiveC *TfliteRangeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc index bb1cd0323e..d4538eaf93 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc @@ -20,36 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteRankParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteRankParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - op->primitive->value.type = schema::PrimitiveType_Rank; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteRankParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -69,6 +39,6 @@ PrimitiveC *TfliteRankParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc index 921b583491..9bc4b43cc4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc @@ -21,70 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteReduceParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->keepDims = tflite_attr->keep_dims; - - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "ReduceMax") == 0) { - MS_LOG(DEBUG) << "parse TfliteReduceMaxParser"; - attr->mode = schema::ReduceMode_ReduceMax; - } else if (std::strcmp(node_name, "ReduceMin") == 0) { - MS_LOG(DEBUG) << "parse TfliteReduceMinParser"; - attr->mode = schema::ReduceMode_ReduceMin; - } else if (std::strcmp(node_name, "ReduceProd") == 0) { - MS_LOG(DEBUG) << "parse TfliteReduceProdParser"; - attr->mode = schema::ReduceMode_ReduceProd; - } else if (std::strcmp(node_name, "Sum") == 0) { - MS_LOG(DEBUG) << "parse TfliteSumParser"; - attr->mode = schema::ReduceMode_ReduceSum; - } else if (std::strcmp(node_name, "Mean") == 0) { - MS_LOG(DEBUG) << "parse TfliteMeanParser"; - attr->mode = schema::ReduceMode_ReduceMean; - } else { - MS_LOG(ERROR) << node_name << " hasn't been supported"; - return RET_NOT_FIND_OP; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->axes)) { - MS_LOG(ERROR) << "get reduce -> axes failed"; - return RET_ERROR; - } - - op->primitive->value.type = schema::PrimitiveType_Reduce; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteReduceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -139,11 +75,11 @@ PrimitiveC *TfliteReduceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc index 92185346c3..b42b24a170 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc @@ -19,69 +19,6 @@ #include namespace mindspore::lite { -STATUS TfliteReshapeParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - MS_LOG(DEBUG) << "parse TfliteReshapeParser"; - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsReshapeOptions(); - if (tflite_attr == nullptr) { - if (tflite_op->inputs.size() < 2) { - MS_LOG(ERROR) << "expected two input tensors, but got: " << tflite_op->inputs.size(); - return RET_ERROR; - } - auto shape_tensor_index = tflite_op->inputs[1]; - const auto &shape_tensor = tflite_subgraph->tensors[shape_tensor_index]; - if (shape_tensor == nullptr) { - MS_LOG(ERROR) << "shape_tensor is null"; - return RET_NULL_PTR; - } - auto &buf_data = tflite_model->buffers[shape_tensor->buffer]; - if (buf_data == nullptr) { - MS_LOG(ERROR) << "buf_data is null"; - return RET_NULL_PTR; - } - if (!buf_data->data.empty()) { - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->shape)) { - MS_LOG(ERROR) << "get reshape -> shape failed"; - return RET_ERROR; - } - } - } else { - attr->format = schema::Format::Format_NHWC; - attr->shape.resize(tflite_attr->new_shape.size()); - for (size_t i = 0; i < tflite_attr->new_shape.size(); ++i) { - attr->shape[i] = tflite_attr->new_shape[i]; - } - } - - op->primitive->value.type = schema::PrimitiveType_Reshape; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} lite::PrimitiveC *TfliteReshapeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { const auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -127,5 +64,5 @@ lite::PrimitiveC *TfliteReshapeParser::ParseLitePrimitive(const std::unique_ptr< return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteReshapeParser("Reshape", new TfliteReshapeParser()); +TfliteNodeRegister g_tfliteReshapeParser(tflite::BuiltinOperator_RESHAPE, new TfliteReshapeParser()); } // namespace mindspore::lite diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.h index 9ac8908245..88f9cfe4f2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.h @@ -28,10 +28,6 @@ class TfliteReshapeParser : public TfliteNodeParser { public: TfliteReshapeParser() : TfliteNodeParser("Reshape") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - lite::PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc index 50db0619c8..321996162e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc @@ -22,104 +22,6 @@ namespace mindspore { namespace lite { -STATUS TfliteResizeParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - attr->coordinateTransformMode = schema::CoordinateTransformMode_COMMON; - std::vector node_name_str; - Split(op->name, &node_name_str, "-"); - const char *node_name = node_name_str.data()->c_str(); - if (std::strcmp(node_name, "ResizeBilinear") == 0) { - MS_LOG(DEBUG) << "parse TfliteResizeBilinearParser"; - const auto &tfliteAttr = tflite_op->builtin_options.AsResizeBilinearOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - if (tfliteAttr->align_corners) { - attr->alignCorners = tfliteAttr->align_corners; - attr->coordinateTransformMode = schema::CoordinateTransformMode_ALIGN_CORNERS; - } - if (tfliteAttr->half_pixel_centers) { - attr->coordinateTransformMode = (attr->coordinateTransformMode == schema::CoordinateTransformMode_COMMON - ? schema::CoordinateTransformMode_TF_HALF_PIXEL - : schema::CoordinateTransformMode_ALIGN_CORNERS_WITH_HALF_PIEXL); - } - attr->method = schema::ResizeMethod_LINEAR; - } else if (std::strcmp(node_name, "NearestNeighbor") == 0) { - MS_LOG(DEBUG) << "parse TfliteResizeNearestNeighborParser"; - const auto &tfliteAttr = tflite_op->builtin_options.AsResizeNearestNeighborOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - if (tfliteAttr->align_corners) { - attr->alignCorners = tfliteAttr->align_corners; - attr->coordinateTransformMode = schema::CoordinateTransformMode_ALIGN_CORNERS; - } - if (tfliteAttr->half_pixel_centers) { - attr->coordinateTransformMode = (attr->coordinateTransformMode == schema::CoordinateTransformMode_COMMON - ? schema::CoordinateTransformMode_TF_HALF_PIXEL - : schema::CoordinateTransformMode_ALIGN_CORNERS_WITH_HALF_PIEXL); - } - attr->method = schema::ResizeMethod_NEAREST; - attr->nearestMode = schema::NearestMode_NORMAL; - } else { - MS_LOG(ERROR) << "wrong resize type"; - return RET_ERROR; - } - - attr->format = schema::Format::Format_NHWC; - attr->preserveAspectRatio = false; - - auto tfliteResizeTensorIndex = tflite_op->inputs[1]; - const auto &shape_tensor = tflite_subgraph->tensors[tfliteResizeTensorIndex]; - if (shape_tensor == nullptr) { - MS_LOG(ERROR) << "shape_tensor is null"; - return RET_NULL_PTR; - } - auto resizeTensorBufferIndex = shape_tensor->buffer; - const auto &buff = tflite_model->buffers.at(resizeTensorBufferIndex); - if (buff == nullptr) { - MS_LOG(ERROR) << "buff_data is null"; - return RET_NULL_PTR; - } - auto buffData = reinterpret_cast(buff->data.data()); - if (buffData != nullptr) { - auto height = buffData[0]; - auto width = buffData[1]; - attr->newWidth = width; - attr->newHeight = height; - } - - op->primitive->value.type = schema::PrimitiveType_Resize; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - if (buffData == nullptr) { - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteResizeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -204,7 +106,8 @@ PrimitiveC *TfliteResizeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc index 7368eced67..21b1fafae7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc @@ -20,41 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteReverseParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteReverseParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->axis)) { - MS_LOG(ERROR) << "get reverse -> axis failed"; - return RET_ERROR; - } - - op->primitive->value.type = schema::PrimitiveType_Reverse; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteReverseParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -80,6 +45,6 @@ PrimitiveC *TfliteReverseParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc index c5f8b7fa6a..ca0e4cf243 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc @@ -21,47 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteReverseSequenceParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, - schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteReverseSequenceParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->seqAxis = tflite_attr->seq_dim; - attr->batchAxis = tflite_attr->batch_dim; - - op->primitive->value.type = schema::PrimitiveType_ReverseSequence; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteReverseSequenceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -89,6 +48,7 @@ PrimitiveC *TfliteReverseSequenceParser::ParseLitePrimitive(const std::unique_pt return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteReverseSequenceParser("ReverseSequence", new TfliteReverseSequenceParser()); +TfliteNodeRegister g_tfliteReverseSequenceParser(tflite::BuiltinOperator_REVERSE_SEQUENCE, + new TfliteReverseSequenceParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.h index ab11a933d0..0118360222 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.h @@ -29,9 +29,6 @@ class TfliteReverseSequenceParser : public TfliteNodeParser { public: TfliteReverseSequenceParser() : TfliteNodeParser("ReverseSequence") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc index 5408eee8e4..44cba14764 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc @@ -20,44 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteScatterNdParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteScatterNdParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsScatterNdOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - op->primitive->value.type = schema::PrimitiveType_ScatterND; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[2], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteScatterNdParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -82,6 +44,6 @@ PrimitiveC *TfliteScatterNdParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc index 8853fca811..7e1b390de3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc @@ -20,36 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteShapeParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteShapeParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - op->primitive->value.type = schema::PrimitiveType_Shape; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteShapeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -69,6 +39,6 @@ PrimitiveC *TfliteShapeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_skip_gram_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_skip_gram_parser.cc index 6378f71adf..5e6efaaaa8 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_skip_gram_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_skip_gram_parser.cc @@ -20,45 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSkipGramParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSkipGramParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsSkipGramOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->includeAllGrams = tflite_attr->include_all_ngrams; - attr->maxSkipSize = tflite_attr->max_skip_size; - attr->ngramSize = tflite_attr->ngram_size; - - op->primitive->value.type = schema::PrimitiveType_SkipGram; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSkipGramParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -87,6 +48,6 @@ PrimitiveC *TfliteSkipGramParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc index d5a62250e0..dd6c92fe22 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc @@ -20,52 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSliceParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSliceParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->format = schema::Format::Format_NHWC; - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->begin)) { - MS_LOG(ERROR) << "get slice -> begin failed"; - return RET_ERROR; - } - if (GetTfliteData(tflite_op->inputs[2], tflite_subgraph->tensors, tflite_model->buffers, attr->size)) { - MS_LOG(ERROR) << "get slice -> size failed"; - return RET_ERROR; - } - std::vector axes; - axes.clear(); - for (size_t i = 0; i < attr->begin.size(); ++i) { - axes.push_back(i); - } - attr->axes = axes; - op->primitive->value.type = schema::PrimitiveType_Slice; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSliceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -102,6 +56,6 @@ PrimitiveC *TfliteSliceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc index 27d515f924..b5e30d7635 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc @@ -19,38 +19,6 @@ #include namespace mindspore::lite { -STATUS TfliteSoftmaxParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSoftmaxParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->axis = -1; - - op->primitive->value.type = schema::PrimitiveType_SoftMax; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSoftmaxParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { @@ -67,5 +35,5 @@ PrimitiveC *TfliteSoftmaxParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; - PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc index fcebe459e8..db6524d7ec 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc @@ -21,47 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSpaceToBatchNDParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, - schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSpaceToBatchNDParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->blockShape)) { - MS_LOG(ERROR) << "get spaceToBatchND -> blockShape failed"; - return RET_ERROR; - } - if (GetTfliteData(tflite_op->inputs[2], tflite_subgraph->tensors, tflite_model->buffers, attr->paddings)) { - MS_LOG(ERROR) << "get spaceToBatchND -> paddings failed"; - return RET_ERROR; - } - - op->primitive->value.type = schema::PrimitiveType_SpaceToBatchND; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSpaceToBatchNDParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -91,6 +50,7 @@ PrimitiveC *TfliteSpaceToBatchNDParser::ParseLitePrimitive(const std::unique_ptr return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteSpaceToBatchNDParser("SpaceToBatchND", new TfliteSpaceToBatchNDParser()); +TfliteNodeRegister g_tfliteSpaceToBatchNDParser(tflite::BuiltinOperator_SPACE_TO_BATCH_ND, + new TfliteSpaceToBatchNDParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.h index fa55f1d681..e7b0e4ae40 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.h @@ -29,9 +29,6 @@ class TfliteSpaceToBatchNDParser : public TfliteNodeParser { public: TfliteSpaceToBatchNDParser() : TfliteNodeParser("SpaceToBatchND") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc index 863e0c5d2c..dabe71094b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc @@ -21,45 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSpaceToDepthParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSpaceToDepthParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsSpaceToDepthOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op:" << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->blockSize = tflite_attr->block_size; - attr->format = schema::Format::Format_NHWC; - - op->primitive->value.type = schema::PrimitiveType_SpaceToDepth; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSpaceToDepthParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -87,6 +48,6 @@ PrimitiveC *TfliteSpaceToDepthParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc index b1cd394429..a7e793a59a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc @@ -21,42 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSparseToDenseParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSparseToDenseParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->validateIndices = false; - - op->primitive->value.type = schema::PrimitiveType_SparseToDense; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[2], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[3], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSparseToDenseParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -77,6 +41,7 @@ PrimitiveC *TfliteSparseToDenseParser::ParseLitePrimitive(const std::unique_ptr< return PrimitiveC::Create(primitive.release()); } -TfliteNodeRegister g_tfliteSparseToDenseParser("SparseToDense", new TfliteSparseToDenseParser()); +TfliteNodeRegister g_tfliteSparseToDenseParser(tflite::BuiltinOperator_SPARSE_TO_DENSE, + new TfliteSparseToDenseParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.h index 6cefe92a67..78a91f4c0b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.h @@ -29,9 +29,6 @@ class TfliteSparseToDenseParser : public TfliteNodeParser { public: TfliteSparseToDenseParser() : TfliteNodeParser("SparseToDense") {} - STATUS Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc index 12bd11c550..b43ca08ece 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc @@ -21,81 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSplitParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSplitParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsSplitOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - auto num_splits = tflite_attr->num_splits; - - const auto &shape_tensor = tflite_subgraph->tensors[tflite_op->inputs[1]]; - if (shape_tensor == nullptr) { - MS_LOG(ERROR) << "shape_tensor is null"; - return RET_NULL_PTR; - } - const auto tensor_shape = shape_tensor->shape; - - const auto &axis_tensor = tflite_subgraph->tensors[tflite_op->inputs[0]]; - if (axis_tensor == nullptr) { - MS_LOG(ERROR) << "axis_tensor is null"; - return RET_NULL_PTR; - } - auto axis = *(reinterpret_cast(tflite_model->buffers[axis_tensor->buffer]->data.data())); - if (axis < 0) { - axis += tensor_shape.size(); - } - if (axis >= static_cast(tensor_shape.size())) { - MS_LOG(ERROR) << "axis value is too large"; - return RET_ERROR; - } - attr->splitDim = axis; - if (num_splits == 0) { - MS_LOG(ERROR) << "Divide-by-zero error!"; - return RET_ERROR; - } - if (tensor_shape[axis] % num_splits != 0 && tensor_shape[axis] / num_splits != 0) { - MS_LOG(ERROR) << "num_splits can't divide tensor's length at axis " << axis; - return RET_ERROR; - } - attr->numberSplit = num_splits; - if (tensor_shape[axis] / num_splits != 0) { - for (int i = 0; i < num_splits; i++) { - attr->sizeSplits.push_back(tensor_shape[axis] / num_splits); - } - } - - op->primitive->value.type = schema::PrimitiveType_Split; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteSplitParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -154,6 +79,6 @@ PrimitiveC *TfliteSplitParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc index 962ab8992a..f0fc6cf380 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc @@ -21,76 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSplitVParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSplitVParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsSplitVOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->numberSplit = tflite_attr->num_splits; - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->sizeSplits)) { - MS_LOG(ERROR) << "get spliteV -> sizeSplits failed"; - return RET_ERROR; - } - - const auto &tensor = tflite_subgraph->tensors[tflite_op->inputs[0]]; - if (tensor == nullptr) { - MS_LOG(ERROR) << "tensor_shape is null"; - return RET_NULL_PTR; - } - auto tensor_shape = tensor->shape; - const auto &axis_tensor = tflite_subgraph->tensors[tflite_op->inputs[2]]; - if (axis_tensor == nullptr) { - MS_LOG(ERROR) << "axis_tensor is null"; - return RET_NULL_PTR; - } - const auto &axis_buf = tflite_model->buffers[axis_tensor->buffer]; - if (axis_buf == nullptr) { - MS_LOG(ERROR) << "axis_buf is null"; - return RET_NULL_PTR; - } - auto axis = *(reinterpret_cast(axis_buf->data.data())); - if (axis < 0) { - axis += tensor_shape.size(); - } - if (axis >= static_cast(tensor_shape.size())) { - MS_LOG(ERROR) << "axis value is too large"; - return RET_ERROR; - } - attr->splitDim = axis; - - op->primitive->value.type = schema::PrimitiveType_Split; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteSplitVParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -144,6 +74,6 @@ PrimitiveC *TfliteSplitVParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc index 58789ba7be..7befade9b7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc @@ -20,43 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteSqueezeParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteSqueezeParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsSqueezeOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->axis = tflite_attr->squeeze_dims; - - op->primitive->value.type = schema::PrimitiveType_Squeeze; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteSqueezeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -83,6 +46,6 @@ PrimitiveC *TfliteSqueezeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc index 2e684cb0a8..7146ce5d55 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc @@ -20,48 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteStackParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteStackParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsPackOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->axis = tflite_attr->axis; - attr->n = tflite_attr->values_count; - attr->isScale.assign(tflite_subgraph->tensors[tflite_op->inputs[0]]->shape.begin(), - tflite_subgraph->tensors[tflite_op->inputs[0]]->shape.end()); - - op->primitive->value.type = schema::PrimitiveType_Stack; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteStackParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -92,6 +50,6 @@ PrimitiveC *TfliteStackParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc index 48a7a34887..5699d98d45 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc @@ -20,70 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteStridedSliceParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteStridedSliceParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - const auto &tflite_attr = tflite_op->builtin_options.AsStridedSliceOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); - return RET_NULL_PTR; - } - attr->beginMask = tflite_attr->begin_mask; - attr->endMask = tflite_attr->end_mask; - attr->ellipsisMask = tflite_attr->ellipsis_mask; - attr->newAxisMask = tflite_attr->new_axis_mask; - attr->shrinkAxisMask = tflite_attr->shrink_axis_mask; - - int status = GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->begin); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "stridedSlice -> begin get failed"; - return RET_ERROR; - } else if (status == RET_OK) { - status = GetTfliteData(tflite_op->inputs[2], tflite_subgraph->tensors, tflite_model->buffers, attr->end); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "stridedSlice -> end get failed"; - return RET_ERROR; - } else if (status == RET_OK) { - status = GetTfliteData(tflite_op->inputs[3], tflite_subgraph->tensors, tflite_model->buffers, attr->stride); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "stridedSlice -> stride get failed"; - return RET_ERROR; - } - } - } - attr->isScale.assign(tflite_subgraph->tensors[tflite_op->inputs[0]]->shape.begin(), - tflite_subgraph->tensors[tflite_op->inputs[0]]->shape.end()); - - op->primitive->value.type = schema::PrimitiveType_StridedSlice; - op->primitive->value.value = attr.release(); - - int input_num = status == RET_OK ? 1 : 4; - for (int i = 0; i < input_num; ++i) { - AddOpInput(op, tensors_info, tflite_op->inputs[i], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteStridedSliceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -135,6 +71,6 @@ PrimitiveC *TfliteStridedSliceParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc index 975f2be160..70b8f2d1b3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc @@ -21,45 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteTileParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteTileParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->multiples)) { - MS_LOG(ERROR) << "get tile -> multiples failed"; - return RET_ERROR; - } - std::vector dims(attr->multiples.size(), 0); - for (size_t i = 0; i < dims.size(); ++i) { - dims[i] = i; - } - attr->dims = dims; - op->primitive->value.type = schema::PrimitiveType_Tile; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteTileParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -89,6 +50,6 @@ PrimitiveC *TfliteTileParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc index d3db4ca03b..26ff69f977 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc @@ -22,46 +22,6 @@ namespace mindspore { namespace lite { -STATUS TfliteTopKV2Parser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteTopKV2Parser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - attr->sorted = true; - std::vector k; - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, k)) { - MS_LOG(ERROR) << "get topKV2 -> k failed"; - return RET_ERROR; - } - attr->k = k.front(); - - op->primitive->value.type = schema::PrimitiveType_TopK; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteTopKV2Parser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -90,6 +50,6 @@ PrimitiveC *TfliteTopKV2Parser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc index 7f928dd2e3..84aec3944c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc @@ -20,43 +20,6 @@ namespace mindspore { namespace lite { -STATUS TfliteTransposeParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteTransposeParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[1], tflite_subgraph->tensors, tflite_model->buffers, attr->perm)) { - MS_LOG(ERROR) << "get transpose -> perm failed"; - return RET_ERROR; - } - attr->conjugate = false; - op->primitive->value.type = schema::PrimitiveType_Transpose; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpInput(op, tensors_info, tflite_op->inputs[1], tflite_subgraph->tensors.size(), schema::Format::Format_KHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteTransposeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -83,6 +46,6 @@ PrimitiveC *TfliteTransposeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc index c2610ab3c5..901ea08090 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc @@ -21,45 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteUniqueParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteUniqueParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsUniqueOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); - return RET_NULL_PTR; - } - attr->outType = GetTfliteDataType(tflite_attr->idx_out_type); - - op->primitive->value.type = schema::PrimitiveType_Unique; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteUniqueParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -86,6 +47,6 @@ PrimitiveC *TfliteUniqueParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc index d495f54d34..869e76bd73 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc @@ -21,46 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteUnstackParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "paser TfliteUnstackParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsUnpackOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); - return RET_NULL_PTR; - } - attr->num = tflite_attr->num; - attr->axis = tflite_attr->axis; - - op->primitive->value.type = schema::PrimitiveType_Unstack; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteUnstackParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -88,6 +48,6 @@ PrimitiveC *TfliteUnstackParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc index 61246c0016..4cb0d19411 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc @@ -21,43 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteWhereParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteWhereParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - if (GetTfliteData(tflite_op->inputs[0], tflite_subgraph->tensors, tflite_model->buffers, attr->condition)) { - MS_LOG(ERROR) << "get where -> condition failed"; - return RET_ERROR; - } - - op->primitive->value.type = schema::PrimitiveType_Where; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteWhereParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto &tflite_subgraph = tflite_model->subgraphs.front(); @@ -83,6 +46,6 @@ PrimitiveC *TfliteWhereParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_while_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_while_parser.cc index b0792a3083..01904ac38f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_while_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_while_parser.cc @@ -21,48 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteWhileParser::Parse(TfliteTensorsInfo *tensors_info, const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteWhileParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - const auto &tflite_attr = tflite_op->builtin_options.AsWhileOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->condSubgraphIndex = tflite_attr->cond_subgraph_index; - attr->bodySubgraphIndex = tflite_attr->body_subgraph_index; - - op->primitive->value.type = schema::PrimitiveType_While; - op->primitive->value.value = attr.release(); - - for (int input : tflite_op->inputs) { - AddOpInput(op, tensors_info, input, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - for (int output : tflite_op->outputs) { - AddOpOutput(op, tensors_info, output, tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - } - return RET_OK; -} PrimitiveC *TfliteWhileParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -91,6 +49,6 @@ PrimitiveC *TfliteWhileParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; }; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc index 19334623f3..2132c53d8f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc @@ -21,37 +21,6 @@ namespace mindspore { namespace lite { -STATUS TfliteZerosLikeParser::Parse(TfliteTensorsInfo *tensors_info, - const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) { - MS_LOG(DEBUG) << "parse TfliteZerosLikeParser"; - MS_ASSERT(tflite_op != nullptr); - MS_ASSERT(tflite_model != nullptr); - MS_ASSERT(tflite_subgraph != nullptr); - if (op == nullptr) { - MS_LOG(ERROR) << "op is null"; - return RET_NULL_PTR; - } - op->primitive = std::make_unique(); - if (op->primitive == nullptr) { - MS_LOG(ERROR) << "op->primitive is null"; - return RET_NULL_PTR; - } - - std::unique_ptr attr = std::make_unique(); - if (attr == nullptr) { - MS_LOG(ERROR) << "new op failed"; - return RET_NULL_PTR; - } - - op->primitive->value.type = schema::PrimitiveType_ZerosLike; - op->primitive->value.value = attr.release(); - - AddOpInput(op, tensors_info, tflite_op->inputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - AddOpOutput(op, tensors_info, tflite_op->outputs[0], tflite_subgraph->tensors.size(), schema::Format::Format_NHWC); - return RET_OK; -} PrimitiveC *TfliteZerosLikeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) { auto primitive = std::make_unique(); @@ -71,6 +40,6 @@ PrimitiveC *TfliteZerosLikeParser::ParseLitePrimitive(const std::unique_ptr &tflite_op, - const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, schema::CNodeT *op) override; PrimitiveC *ParseLitePrimitive(const std::unique_ptr &tflite_op, const std::unique_ptr &tflite_model) override; };