diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index f8f1115ec8..868b7ed6a5 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -1,5 +1,7 @@ +set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(TEST_DIR ${TOP_DIR}/mindspore/lite/test) set(LITE_DIR ${TOP_DIR}/mindspore/lite) +set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc) include_directories(${TOP_DIR}) include_directories(${TEST_DIR}) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake) @@ -12,6 +14,7 @@ set(ANF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../core/base/base.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../core/utils/log_adapter.cc ) + if(BUILD_CONVERTER) set(ANF_SRC ${ANF_SRC} diff --git a/mindspore/lite/test/run_test.sh b/mindspore/lite/test/run_test.sh index adfb48130f..f048dbb364 100755 --- a/mindspore/lite/test/run_test.sh +++ b/mindspore/lite/test/run_test.sh @@ -26,3 +26,5 @@ cp -fr $TEST_DATA_DIR/testPK ./data ./lite-test --gtest_filter=TestPadInt8.* ./lite-test --gtest_filter=TestDeconvInt8.* + +./lite-test --gtest_filter="TestTfliteParser*" diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite new file mode 100644 index 0000000000..762c2e7d3f Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite new file mode 100644 index 0000000000..c0c379a60c Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite new file mode 100644 index 0000000000..d36b81e327 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite new file mode 100644 index 0000000000..05b172c71e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite new file mode 100644 index 0000000000..75b2d77d30 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite new file mode 100644 index 0000000000..6ba493eebf Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite new file mode 100644 index 0000000000..bc367d8f1e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite new file mode 100644 index 0000000000..a8b7e5ec7b Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite new file mode 100644 index 0000000000..b76878f102 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite new file mode 100644 index 0000000000..7e87baac9e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite new file mode 100644 index 0000000000..9a24dbd20c Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite new file mode 100644 index 0000000000..3bf705e36d Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite new file mode 100644 index 0000000000..b101b93076 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite new file mode 100644 index 0000000000..422ff5c51e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite new file mode 100644 index 0000000000..9fe5da76ba Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite new file mode 100644 index 0000000000..ba8c13f363 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite new file mode 100644 index 0000000000..a5a20a1ddf Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite new file mode 100644 index 0000000000..0621a681ac Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite new file mode 100644 index 0000000000..089de5cb2d Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite new file mode 100644 index 0000000000..a0b90cde82 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite new file mode 100644 index 0000000000..bc5c86a334 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite new file mode 100644 index 0000000000..2920f9ae4e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite new file mode 100644 index 0000000000..6e9afb7bab Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite new file mode 100644 index 0000000000..8733544eba Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite new file mode 100644 index 0000000000..a99a4ddce8 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite new file mode 100644 index 0000000000..6a55540324 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite new file mode 100644 index 0000000000..96b50b4e23 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite new file mode 100644 index 0000000000..d636c870ec Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite new file mode 100644 index 0000000000..7eb0678150 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite new file mode 100644 index 0000000000..8e3b3aaf80 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite new file mode 100644 index 0000000000..dbca4e40a1 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite new file mode 100644 index 0000000000..c223cdbf90 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc index c90ff924a1..7f0453bd11 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserAbs : public TestTfliteParser { public: - TestTfliteParserAbs() {} + TestTfliteParserAbs() = default; void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc new file mode 100644 index 0000000000..d590be8131 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserAdd1 : public TestTfliteParser { + public: + TestTfliteParserAdd1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add1.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserAdd2 : public TestTfliteParser { + public: + TestTfliteParserAdd2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add2.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserAdd3 : public TestTfliteParser { + public: + TestTfliteParserAdd3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add3.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc index 89519cea10..72a8237673 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserAddN : public TestTfliteParser { public: - TestTfliteParserAddN() {} + TestTfliteParserAddN() = default; void SetUp() override { meta_graph = LoadAndConvert("./addn.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc new file mode 100644 index 0000000000..0bb625ec87 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserArgmin : public TestTfliteParser { + public: + TestTfliteParserArgmin() = default; + void SetUp() override { meta_graph = LoadAndConvert("./argmin.tflite", ""); } +}; + +TEST_F(TestTfliteParserArgmin, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_ArgMin) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserArgmin, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsArgMin(); + ASSERT_EQ(val->axis, 1); + ASSERT_EQ(val->topK, 1); + ASSERT_EQ(val->axisType, 1); + ASSERT_EQ(val->keepDims, false); + ASSERT_EQ(val->outMaxValue, false); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc index 4d37fa506a..c78d8eac54 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserBatchToSpaceNd : public TestTfliteParser { public: - TestTfliteParserBatchToSpaceNd() {} + TestTfliteParserBatchToSpaceNd() = default; void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc index c986d595d7..28fe10828c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserCast : public TestTfliteParser { public: - TestTfliteParserCast() {} + TestTfliteParserCast() = default; void SetUp() override { meta_graph = LoadAndConvert("./cast.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc new file mode 100644 index 0000000000..59d8664be1 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserCeil : public TestTfliteParser { + public: + TestTfliteParserCeil() = default; + void SetUp() override { meta_graph = LoadAndConvert("./ceil.tflite", ""); } +}; + +TEST_F(TestTfliteParserCeil, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Ceil) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc index 785cd35e44..756cd626c6 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserCos : public TestTfliteParser { public: - TestTfliteParserCos() {} + TestTfliteParserCos() = default; void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc index d1983e0b84..5283c0a85d 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserDepthToSpace : public TestTfliteParser { public: - TestTfliteParserDepthToSpace() {} + TestTfliteParserDepthToSpace() = default; void SetUp() override { meta_graph = LoadAndConvert("./depth_to_space.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc new file mode 100644 index 0000000000..8ee47212a4 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserDiv1 : public TestTfliteParser { + public: + TestTfliteParserDiv1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div1.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserDiv2 : public TestTfliteParser { + public: + TestTfliteParserDiv2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div2.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserDiv3 : public TestTfliteParser { + public: + TestTfliteParserDiv3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div3.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc index 7e816a9d39..ba2e4b0f51 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserEqual : public TestTfliteParser { public: - TestTfliteParserEqual() {} + TestTfliteParserEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc new file mode 100644 index 0000000000..359d54b6e5 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFill : public TestTfliteParser { + public: + TestTfliteParserFill() = default; + void SetUp() override { meta_graph = LoadAndConvert("./fill.tflite", ""); } +}; + +TEST_F(TestTfliteParserFill, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Fill) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserFill, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsFill(); + + std::vector dims = {9}; + ASSERT_EQ(val->dims, dims); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc new file mode 100644 index 0000000000..d92c1608a7 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloorDiv : public TestTfliteParser { + public: + TestTfliteParserFloorDiv() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor_div.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloorDiv, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_FloorDiv) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc new file mode 100644 index 0000000000..f8cf0fdf03 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloorMod : public TestTfliteParser { + public: + TestTfliteParserFloorMod() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor_mod.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloorMod, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_FloorMod) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc new file mode 100644 index 0000000000..d7777f24b9 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloor : public TestTfliteParser { + public: + TestTfliteParserFloor() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloor, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Floor) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc new file mode 100644 index 0000000000..d6badec6a7 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGatherNd : public TestTfliteParser { + public: + TestTfliteParserGatherNd() = default; + void SetUp() override { meta_graph = LoadAndConvert("./gather_nd.tflite", ""); } +}; + +TEST_F(TestTfliteParserGatherNd, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_GatherNd) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserGatherNd, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsGatherNd(); + ASSERT_EQ(val->batchDims, 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc new file mode 100644 index 0000000000..13420abada --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGather : public TestTfliteParser { + public: + TestTfliteParserGather() = default; + void SetUp() override { meta_graph = LoadAndConvert("./gather.tflite", ""); } +}; + +TEST_F(TestTfliteParserGather, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Gather) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserGather, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsGather(); + ASSERT_EQ(val->axis, 0); + ASSERT_EQ(val->batchDims, 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc index 3b5dba47c2..c65b80cc88 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserGreaterEqual : public TestTfliteParser { public: - TestTfliteParserGreaterEqual() {} + TestTfliteParserGreaterEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./greater_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc index 055dbab7da..b765fc8d85 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserGreater : public TestTfliteParser { public: - TestTfliteParserGreater() {} + TestTfliteParserGreater() = default; void SetUp() override { meta_graph = LoadAndConvert("./greater.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc new file mode 100644 index 0000000000..80c8826088 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLeakyRelu : public TestTfliteParser { + public: + TestTfliteParserLeakyRelu() = default; + void SetUp() override { meta_graph = LoadAndConvert("./leaky_relu.tflite", ""); } +}; + +TEST_F(TestTfliteParserLeakyRelu, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_LeakyReLU) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserLeakyRelu, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsLeakyReLU(); + ASSERT_NE(val, nullptr); + ASSERT_EQ(val->negativeSlope, 0.20000000298023224); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc index 6c1d29877f..06f57a4bab 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserLessEqual : public TestTfliteParser { public: - TestTfliteParserLessEqual() {} + TestTfliteParserLessEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./less_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc index 795acfce7d..1872d2d3f1 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserLess : public TestTfliteParser { public: - TestTfliteParserLess() {} + TestTfliteParserLess() = default; void SetUp() override { meta_graph = LoadAndConvert("./less.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc index fe869019ce..22976eceb8 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLog : public TestTfliteParser { public: - TestTfliteParserLog() {} + TestTfliteParserLog() = default; void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc index 415dc874ee..a1a5159ae0 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteLogicalParserAnd : public TestTfliteParser { public: - TestTfliteLogicalParserAnd() {} + TestTfliteLogicalParserAnd() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc index a34ae07afe..cb2c21411e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLogicalNot : public TestTfliteParser { public: - TestTfliteParserLogicalNot() {} + TestTfliteParserLogicalNot() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc index 19141d6125..508293542f 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLogicalOr : public TestTfliteParser { public: - TestTfliteParserLogicalOr() {} + TestTfliteParserLogicalOr() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc new file mode 100644 index 0000000000..88a504a6ae --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLRN : public TestTfliteParser { + public: + TestTfliteParserLRN() = default; + void SetUp() override { meta_graph = LoadAndConvert("./lrn.tflite", ""); } +}; + +TEST_F(TestTfliteParserLRN, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, + schema::PrimitiveType_LocalResponseNormalization) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserLRN, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsLocalResponseNormalization(); + ASSERT_EQ(val->alpha, 1); + ASSERT_EQ(val->beta, 0.5); + ASSERT_EQ(val->bias, 1); + ASSERT_EQ(val->depth_radius, 5); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc index a21dba4d8b..b99119df5a 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserMaximum : public TestTfliteParser { public: - TestTfliteParserMaximum() {} + TestTfliteParserMaximum() = default; void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc index 2999d33b16..431a15e5bd 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserMinimum : public TestTfliteParser { public: - TestTfliteParserMinimum() {} + TestTfliteParserMinimum() = default; void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc new file mode 100644 index 0000000000..140960e53b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserMul1 : public TestTfliteParser { + public: + TestTfliteParserMul1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul1.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserMul2 : public TestTfliteParser { + public: + TestTfliteParserMul2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul2.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserMul3 : public TestTfliteParser { + public: + TestTfliteParserMul3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul3.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc index e7260a1262..3e697c862e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserNotEqual : public TestTfliteParser { public: - TestTfliteParserNotEqual() {} + TestTfliteParserNotEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./not_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc index f1f007e849..ed3d946a96 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserOneHot : public TestTfliteParser { public: - TestTfliteParserOneHot() {} + TestTfliteParserOneHot() = default; void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc index 11e5fe7c14..7b64cb1d02 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserPrelu : public TestTfliteParser { public: - TestTfliteParserPrelu() {} + TestTfliteParserPrelu() = default; void SetUp() override { meta_graph = LoadAndConvert("./prelu.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc new file mode 100644 index 0000000000..ada4657759 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPad : public TestTfliteParser { + public: + TestTfliteParserPad() = default; + void SetUp() override { meta_graph = LoadAndConvert("./pad.tflite", ""); } +}; + +TEST_F(TestTfliteParserPad, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Pad) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPad, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsPad(); + + std::vector paddings = {1, 1, 2, 2, 3, 3, 4, 4}; + ASSERT_EQ(val->paddings, paddings); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc index 881d95b89f..66ec6ad1ec 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc @@ -22,9 +22,12 @@ namespace mindspore { schema::MetaGraphT *TestTfliteParser::LoadAndConvert(const string &model_path, const string &weight_path) { - schema::MetaGraphT *meta_graph = nullptr; lite::TfliteModelParser parser; meta_graph = parser.Parse(model_path, weight_path); + if (meta_graph == nullptr) { + MS_LOG(ERROR) << "Parse to metaGraph return nullptr"; + return nullptr; + } return meta_graph; } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h index cf592570c3..200e322c7c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h @@ -24,10 +24,10 @@ namespace mindspore { class TestTfliteParser : public Common { public: - TestTfliteParser() {} + TestTfliteParser() = default; void TearDown() override; schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); - schema::MetaGraphT *meta_graph; + schema::MetaGraphT *meta_graph = nullptr; }; } // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc new file mode 100644 index 0000000000..52188a5d9b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPow : public TestTfliteParser { + public: + TestTfliteParserPow() = default; + void SetUp() override { meta_graph = LoadAndConvert("./pow.tflite", ""); } +}; + +TEST_F(TestTfliteParserPow, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Power) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPow, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsPower(); + + ASSERT_EQ(val->scale, 1.0); + ASSERT_EQ(val->shift, 0.0); + ASSERT_EQ(val->power, 0.0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc index 6c2ff57114..8b5c97a3f8 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceMax : public TestTfliteParser { public: - TestTfliteParserReduceMax() {} + TestTfliteParserReduceMax() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc index dce6a95fb0..01995e9bba 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceMin : public TestTfliteParser { public: - TestTfliteParserReduceMin() {} + TestTfliteParserReduceMin() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc index dc19ad983f..2b0352231f 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceProd : public TestTfliteParser { public: - TestTfliteParserReduceProd() {} + TestTfliteParserReduceProd() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc new file mode 100644 index 0000000000..a0d44c30cd --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserRelu : public TestTfliteParser { + public: + TestTfliteParserRelu() = default; + void SetUp() override { meta_graph = LoadAndConvert("./relu.tflite", ""); } +}; + +TEST_F(TestTfliteParserRelu, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Activation) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc new file mode 100644 index 0000000000..199c560f13 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserResizeNN : public TestTfliteParser { + public: + TestTfliteParserResizeNN() = default; + void SetUp() override { meta_graph = LoadAndConvert("./resize_nearest_neighbor.tflite", ""); } +}; + +TEST_F(TestTfliteParserResizeNN, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Resize) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserResizeNN, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsResize(); + + ASSERT_EQ(val->alignCorners, false); + ASSERT_EQ(val->newHeight, 3); + ASSERT_EQ(val->newWidth, 100); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc new file mode 100644 index 0000000000..ea1ffff935 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReverse : public TestTfliteParser { + public: + TestTfliteParserReverse() = default; + void SetUp() override { meta_graph = LoadAndConvert("./reverse.tflite", ""); } +}; + +TEST_F(TestTfliteParserReverse, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reverse) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReverse, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsReverse(); + + std::vector axis = {3}; + ASSERT_EQ(val->axis, axis); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc index f1a972f6e4..a5f3e58d99 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserReverseSequence : public TestTfliteParser { public: - TestTfliteParserReverseSequence() {} + TestTfliteParserReverseSequence() = default; void SetUp() override { meta_graph = LoadAndConvert("./reverse_sequence.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc index ffb6a26ffe..9ec5ed9b21 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserRound : public TestTfliteParser { public: - TestTfliteParserRound() {} + TestTfliteParserRound() = default; void SetUp() override { meta_graph = LoadAndConvert("./round.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc index c1db7380cb..9b8afe78b3 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserRsqrt : public TestTfliteParser { public: - TestTfliteParserRsqrt() {} + TestTfliteParserRsqrt() = default; void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc index a859cabc87..6ad75bb28c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSin : public TestTfliteParser { public: - TestTfliteParserSin() {} + TestTfliteParserSin() = default; void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc index a9d66ceaf4..dab7110c1a 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSpaceToBatchND : public TestTfliteParser { public: - TestTfliteParserSpaceToBatchND() {} + TestTfliteParserSpaceToBatchND() = default; void SetUp() override { meta_graph = LoadAndConvert("./space_to_batch_nd.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc index 76245204a7..785baff517 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSpaceToDepth : public TestTfliteParser { public: - TestTfliteParserSpaceToDepth() {} + TestTfliteParserSpaceToDepth() = default; void SetUp() override { meta_graph = LoadAndConvert("./space_to_depth.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc index 043fdbfe63..93e7badacf 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSparseToDense : public TestTfliteParser { public: - TestTfliteParserSparseToDense() {} + TestTfliteParserSparseToDense() = default; void SetUp() override { meta_graph = LoadAndConvert("./sparse_to_dense.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc index aae2b629d1..b7c9e38cb9 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSplit : public TestTfliteParser { public: - TestTfliteParserSplit() {} + TestTfliteParserSplit() = default; void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc index 30a7049a42..76eb564247 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSplitV : public TestTfliteParser { public: - TestTfliteParserSplitV() {} + TestTfliteParserSplitV() = default; void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc index 427907dc70..e66b0cb938 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSqrt : public TestTfliteParser { public: - TestTfliteParserSqrt() {} + TestTfliteParserSqrt() = default; void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc index 96e0e71f0c..7bbfeb3eae 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSquare : public TestTfliteParser { public: - TestTfliteParserSquare() {} + TestTfliteParserSquare() = default; void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc index f6be7a992d..74548b4d76 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSquaredDifference : public TestTfliteParser { public: - TestTfliteParserSquaredDifference() {} + TestTfliteParserSquaredDifference() = default; void SetUp() override { meta_graph = LoadAndConvert("./squared_difference.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc index bbb327b998..88177cd9aa 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserStridedSlice : public TestTfliteParser { public: - TestTfliteParserStridedSlice() {} + TestTfliteParserStridedSlice() = default; void SetUp() override { meta_graph = LoadAndConvert("./strided_slice.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc new file mode 100644 index 0000000000..3b9c0e26a6 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSub1 : public TestTfliteParser { + public: + TestTfliteParserSub1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub1.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserSub2 : public TestTfliteParser { + public: + TestTfliteParserSub2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub2.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserSub3 : public TestTfliteParser { + public: + TestTfliteParserSub3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub3.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc index f028516da2..49a5a2f091 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSum : public TestTfliteParser { public: - TestTfliteParserSum() {} + TestTfliteParserSum() = default; void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc index 19401218f7..e025bad6f9 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserTile : public TestTfliteParser { public: - TestTfliteParserTile() {} + TestTfliteParserTile() = default; void SetUp() override { meta_graph = LoadAndConvert("./tile.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc index d358fdb2d5..68e3629611 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserTopKV2 : public TestTfliteParser { public: - TestTfliteParserTopKV2() {} + TestTfliteParserTopKV2() = default; void SetUp() override { meta_graph = LoadAndConvert("./topk_v2.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc index 244abf8ee2..5b49883b78 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserUnique : public TestTfliteParser { public: - TestTfliteParserUnique() {} + TestTfliteParserUnique() = default; void SetUp() override { meta_graph = LoadAndConvert("./unique.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc index e2c03a5bec..9c8e59232e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserUnstack : public TestTfliteParser { public: - TestTfliteParserUnstack() {} + TestTfliteParserUnstack() = default; void SetUp() override { meta_graph = LoadAndConvert("./unstack.tflite"); } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc index 2ec1f0257d..79ca078daf 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_abs_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_abs_parser.h" namespace mindspore { namespace lite { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc index 3981b4b6ae..2976b96473 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc @@ -24,9 +24,7 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteAddParser"; std::unique_ptr attr(new schema::AddT()); const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); @@ -34,14 +32,46 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - return RET_ERROR; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Add; 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 5dc9ee5bfd..5dd1bffd61 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc @@ -15,22 +15,22 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_addn_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_addn_parser.h" namespace mindspore { namespace lite { -STATUS TfliteAddNParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) { +STATUS TfliteAddNParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteAddNParser"; std::unique_ptr attr(new schema::AddNT()); - attr->N = tflite_tensors.size() - 1; + + attr->N = tfliteTensors.size() - 1; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_AddN; 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 30706902b8..832c881044 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc @@ -29,11 +29,25 @@ STATUS TfliteArgmaxParser::Parse(const std::unique_ptr &tflit bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteArgmaxParser"; std::unique_ptr attr(new schema::ArgMaxT()); - // These are caffe attributes, set to default value. - attr->axisType = 1; + attr->outMaxValue = false; attr->topK = 1; attr->keepDims = false; + attr->axisType = 1; + + auto axis_idx = tfliteOp->inputs[1]; + std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); + auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; + 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))); if (op != nullptr) { op->primitive = std::make_unique(); 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 2ff86ae045..56cdec82f4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc @@ -24,29 +24,29 @@ STATUS TfliteArgminParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteArgminParser"; std::unique_ptr attr(new schema::ArgMinT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsArgMinOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - // get axis + attr->outMaxValue = false; + attr->topK = 1; + attr->keepDims = false; + attr->axisType = 1; + auto axis_idx = tfliteOp->inputs[1]; std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; + 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))); - // the following use default values - attr->outMaxValue = false; - attr->topK = 1; - attr->keepDims = false; - attr->axisType = 0; - if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ArgMin; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc index 6ed52bfb12..3ddb49bac2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h" namespace mindspore { namespace lite { @@ -32,11 +32,11 @@ STATUS TfliteBatchToSpaceNDParser::Parse(const std::unique_ptrinputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { - MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed"; + MS_LOG(ERROR) << "get BatchToSpaceNd -> blockShape failed"; return RET_ERROR; } if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->crops)) { - MS_LOG(ERROR) << "BatchToSpaceNd get crops attr failed"; + MS_LOG(ERROR) << "get BatchToSpaceNd -> crops failed"; return RET_ERROR; } 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 6fe391f4b6..00514a098f 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 @@ -15,26 +15,26 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_batch_to_space_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_batch_to_space_parser.h" namespace mindspore { namespace lite { -STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteBatchToSpaceParser"; std::unique_ptr attr(new schema::BatchToSpaceT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) { - MS_LOG(ERROR) << "batchToSpace -> blockShape get failed"; + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { + MS_LOG(ERROR) << "get batchToSpace -> blockShape failed"; return RET_ERROR; } - if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->crops)) { - MS_LOG(ERROR) << "batchToSpace -> crops get failed"; + if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->crops)) { + MS_LOG(ERROR) << "get batchToSpace -> crops failed"; return RET_ERROR; } 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 bc508ef7d6..6c6cd70568 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 @@ -15,31 +15,31 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_broadcast_to_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_broadcast_to_parser.h" namespace mindspore { namespace lite { -STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteBroadcastToParser"; std::unique_ptr attr(new schema::BroadcastToT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->dst_shape)) { - MS_LOG(ERROR) << "broadCastTo -> dst_shape get failed"; + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->dst_shape)) { + MS_LOG(ERROR) << "get broadCastTo -> dst_shape failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_BroadcastTo; - op->primitive->value.value = attr.release(); - } - return RET_OK; + if (op != nullptr) { + op->primitive = std::make_unique(); + op->primitive->value.type = schema::PrimitiveType_BroadcastTo; + op->primitive->value.value = attr.release(); + } + return RET_OK; } TfliteNodeRegister g_tfliteBroadcastToParser("BroadcastTo", new TfliteBroadcastToParser()); 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 a7cce134a6..c8d71de685 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc @@ -15,23 +15,33 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_cast_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_cast_parser.h" namespace mindspore { namespace lite { -STATUS TfliteCastParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteCastParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteCastParser"; std::unique_ptr attr(new schema::CastT()); - attr->srcT = dtype_map[tflite_tensors[tflite_op->inputs[0]]->type]; - attr->dstT = dtype_map[tflite_tensors[tflite_op->outputs[0]]->type]; + const auto &in_tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (in_tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + attr->srcT = dtype_map[in_tensor->type]; + + const auto &out_tensor = tfliteTensors[tfliteOp->outputs[0]]; + if (out_tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + attr->dstT = dtype_map[out_tensor->type]; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc index c8902c5f41..de924ce6b8 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_ceil_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_ceil_parser.h" namespace mindspore { namespace lite { @@ -24,9 +24,7 @@ STATUS TfliteCeilParser::Parse(const std::unique_ptr &tfliteO const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteCeilParser"; std::unique_ptr attr(new schema::CeilT()); 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 5dbe6b2fea..31c7174799 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_concat_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_concat_parser.h" namespace mindspore { namespace lite { @@ -24,18 +24,17 @@ STATUS TfliteConcatParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteConcatParser"; std::unique_ptr attr(new schema::ConcatT()); + const auto &tfliteAttr = tfliteOp->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 = tfliteOp->inputs.size(); if (op != nullptr) { 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 66c2c13492..6a32fa75dd 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc @@ -14,21 +14,20 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_conv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_conv_parser.h" namespace mindspore { namespace lite { -STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, +STATUS TfliteConvParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteConvParser"; std::unique_ptr attr(new schema::Conv2DT()); - const auto &tfliteAttr = tflite_op->builtin_options.AsConv2DOptions(); + const auto &tfliteAttr = tfliteOp->builtin_options.AsConv2DOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; @@ -41,11 +40,15 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_ attr->padMode = GetPadMode(tfliteAttr->padding); attr->format = schema::Format_NHWC; attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_tensors[weight_index]; + auto weight_index = tfliteOp->inputs[1]; + const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; @@ -55,16 +58,23 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_ attr->channelOut = weight_shape[KHWC_K]; attr->kernelW = weight_shape[KHWC_W]; attr->kernelH = weight_shape[KHWC_H]; - if (tflite_op->inputs.size() == 3) { + + // get the conv op bias tensor + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; - auto bias_index = tflite_op->inputs[2]; - const auto &bias_tensor = tflite_tensors[bias_index]; + auto bias_index = tfliteOp->inputs[2]; + const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { MS_LOG(ERROR) << "parse bias failed"; return RET_ERROR; } } + // calculate pad params if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc index a61d95aaf7..3696bc5212 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc @@ -14,17 +14,17 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_cos_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_cos_parser.h" namespace mindspore { namespace lite { STATUS TfliteCosParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteCosParser"; std::unique_ptr attr(new schema::CosT()); 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 50ca889d87..606cccd1a2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc @@ -14,25 +14,25 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_deconv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_deconv_parser.h" namespace mindspore { namespace lite { -STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_op_set, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse tflite Transpose_Conv parser"; std::unique_ptr attr(new schema::DeConv2DT()); - const auto &tflite_attr = tflite_op->builtin_options.AsTransposeConvOptions(); + const auto &tflite_attr = tfliteOp->builtin_options.AsTransposeConvOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } + attr->group = 1; attr->strideW = tflite_attr->stride_w; attr->strideH = tflite_attr->stride_h; @@ -40,12 +40,16 @@ STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflit attr->dilateW = 1; attr->padMode = GetPadMode(tflite_attr->padding); attr->format = schema::Format_NHWC; + // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_tensors[weight_index]; + auto weight_index = tfliteOp->inputs[1]; + const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; - - if (RET_OK != ParseWeight(weight_tensors, tflite_model_buffer, tensor_cache, schema::Format_KHWC)) { + if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { return RET_ERROR; } auto weight_shape = weight_tensor->shape; 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 0c441396c8..ed9c897003 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 @@ -15,26 +15,27 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_depth_to_space_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_depth_to_space_parser.h" namespace mindspore { namespace lite { -STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteDepthToSpaceParser"; std::unique_ptr attr(new schema::DepthToSpaceT()); - const auto &tflite_attr = tflite_op->builtin_options.AsDepthToSpaceOptions(); + + const auto &tflite_attr = tfliteOp->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_NHWC; if (op != nullptr) { 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 0d231d73dd..7c4e8d9225 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 @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_depthwise_conv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_depthwise_conv_parser.h" #include "tools/common/node_util.h" namespace mindspore { @@ -26,6 +26,7 @@ STATUS TfliteDepthwiseConv2DParser::ParseGroupDepthwiseConv(schema::CNodeT *op, const std::unique_ptr &weightTensor, TensorCache *tensor_cache) { std::unique_ptr convAttr(new schema::Conv2DT); + convAttr->format = attr->format; convAttr->channelIn = attr->channelIn; convAttr->channelOut = attr->channelIn * attr->channelMultiplier; @@ -64,9 +65,12 @@ STATUS TfliteDepthwiseConv2DParser::ParseGroupDepthwiseConv(schema::CNodeT *op, } } } - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Conv2D; - op->primitive->value.value = convAttr.release(); + + if (op != nullptr) { + op->primitive = std::make_unique(); + op->primitive->value.type = schema::PrimitiveType_Conv2D; + op->primitive->value.value = convAttr.release(); + } return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc index b7b6efe123..f55652515c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_div_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_div_parser.h" namespace mindspore { namespace lite { @@ -24,25 +24,55 @@ STATUS TfliteDivParser::Parse(const std::unique_ptr &tfliteOp const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteDivParser"; std::unique_ptr attr(new schema::DivT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsDivOptions(); - if (tfliteAttr == nullptr) { + 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); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Div; 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 3c42bf4d3b..21172cb4f9 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 @@ -29,24 +29,26 @@ STATUS TfliteExpandDimsParser::Parse(const std::unique_ptr &t bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteExpandDimsParser"; std::unique_ptr attr(new schema::ExpandDimsT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsExpandDimsOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - // get axis - auto axis_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); - auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; - auto data_ptr = buf_data->data.data(); - attr->dim = *(static_cast(static_cast(data_ptr))); + attr->dim = -1; + + MS_LOG(ERROR) << "The attr dim is folded by TFLite."; + return RET_ERROR; + /* if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ExpandDims; op->primitive->value.value = attr.release(); } return RET_OK; + */ } TfliteNodeRegister g_tfliteExpandDimsParser("ExpandDims", new TfliteExpandDimsParser()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc index 9d2dfddcfb..b785eb4b1e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc @@ -29,15 +29,24 @@ STATUS TfliteFakeQuantParser::Parse(const std::unique_ptr &tf auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; auto bias_index = tfliteOp->inputs[2]; const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { MS_LOG(ERROR) << "parse bias failed"; @@ -45,6 +54,7 @@ STATUS TfliteFakeQuantParser::Parse(const std::unique_ptr &tf } } attr->axis = 1; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_FullConnection; 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 e41141b560..06b56df1e5 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc @@ -32,6 +32,7 @@ STATUS TfliteFillParser::Parse(const std::unique_ptr &tfliteO if (tfliteOp->inputs.size() > 1) { if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->dims)) { + MS_LOG(ERROR) << "get Fill -> dims failed"; return RET_ERROR; } } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc index 70abaef920..2325cd07be 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc @@ -38,7 +38,7 @@ STATUS TfliteFloorParser::Parse(const std::unique_ptr &tflite return RET_OK; } -TfliteNodeRegister g_tfliteFloorParser("Floor", new TfliteFloorParser()); +TfliteNodeRegister g_tfliteFloorParser("flOOR", new TfliteFloorParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h index 7db0e83324..6f828a1e50 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteFloorParser : public TfliteNodeParser { public: - TfliteFloorParser() : TfliteNodeParser("Floor") {} + TfliteFloorParser() : TfliteNodeParser("flOOR") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, 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 8ee363335f..61e40382ae 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc @@ -30,16 +30,24 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptrinputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; - + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; auto bias_index = tfliteOp->inputs[2]; const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { MS_LOG(ERROR) << "parse bias failed"; @@ -47,6 +55,7 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptraxis = 1; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_FullConnection; 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 41841f4a28..18b4d49aa0 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 @@ -29,12 +29,8 @@ STATUS TfliteGatherNdParser::Parse(const std::unique_ptr &tfl bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteGatherNdParser"; std::unique_ptr attr(new schema::GatherNdT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsGatherNdOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - attr->batchDims = 0; // default + attr->batchDims = 0; if (op != nullptr) { op->primitive = std::make_unique(); @@ -44,7 +40,7 @@ STATUS TfliteGatherNdParser::Parse(const std::unique_ptr &tfl return RET_OK; } -TfliteNodeRegister g_tfliteGatherNdParser("GatherNd", new TfliteGatherNdParser()); +TfliteNodeRegister g_tfliteGatherNdParser("GatherND", new TfliteGatherNdParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h index 18b8b5531d..c79d8aa753 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteGatherNdParser : public TfliteNodeParser { public: - TfliteGatherNdParser() : TfliteNodeParser("GatherNd") {} + TfliteGatherNdParser() : TfliteNodeParser("GatherND") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, 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 4c9efde2b4..2526e1665f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc @@ -29,13 +29,15 @@ STATUS TfliteGatherParser::Parse(const std::unique_ptr &tflit bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteGatherParser"; std::unique_ptr attr(new schema::GatherT()); + const auto &tflite_attr = tfliteOp->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; // default + + attr->batchDims = 0; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc deleted file mode 100644 index 514fe5280c..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "tools/converter/parser/tflite/tflite_gather_v2_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteGatherV2Parser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteGatherV2Parser"; - std::unique_ptr attr(new schema::GatherT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsGatherOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - attr->axis = tflite_attr->axis; - attr->batchDims = 0; // default - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Gather; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteGatherV2Parser("GatherV2", new TfliteGatherV2Parser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h deleted file mode 100644 index d9acc3721d..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PREDICT_TFLITE_GATHER_V2_PARSER_H -#define PREDICT_TFLITE_GATHER_V2_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteGatherV2Parser : public TfliteNodeParser { - public: - TfliteGatherV2Parser() : TfliteNodeParser("GatherV2") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_GATHER_V2_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc deleted file mode 100644 index aaf9366e81..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "tools/converter/parser/tflite/tflite_inner_product_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteInnerProductParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteInnerProductParser"; - std::unique_ptr attr(new schema::FullConnectionT()); - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; - } - if (tfliteOp->inputs.size() == 3) { - attr->hasBias = true; - auto bias_index = tfliteOp->inputs[2]; - const auto &bias_tensor = tfliteTensors[bias_index]; - std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { - MS_LOG(ERROR) << "parse bias failed"; - return RET_ERROR; - } - } - attr->axis = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FullConnection; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteInnerProductParser("InnerProduct", new TfliteInnerProductParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h deleted file mode 100644 index 0505e8ce23..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PREDICT_TFLITE_INNER_PRODUCT_PARSER_H -#define PREDICT_TFLITE_INNER_PRODUCT_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteInnerProductParser : public TfliteNodeParser { - public: - TfliteInnerProductParser() : TfliteNodeParser("InnerProduct") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_INNER_PRODUCT_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc index f04c65c4d3..c805e6f649 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc @@ -27,16 +27,17 @@ STATUS TfliteLeakyReluParser::Parse(const std::unique_ptr &tf schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteLeakyReluParser"; std::unique_ptr attr(new schema::LeakyReLUT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsLeakyReluOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->negativeSlope = tflite_attr->alpha; if (op != nullptr) { op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; + op->primitive->value.type = schema::PrimitiveType_LeakyReLU; op->primitive->value.value = attr.release(); } return RET_OK; 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 3ac19a2920..789d2ec203 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc @@ -29,11 +29,12 @@ STATUS TfliteLRNParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteLRNParser"; std::unique_ptr attr(new schema::LocalResponseNormalizationT()); + const auto &tflite_attr = tfliteOp->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; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc index 387b0302e2..7658a04a4a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc @@ -31,7 +31,9 @@ STATUS TfliteMaxPoolingParser::Parse(const std::unique_ptr &t 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->format = schema::Format_NHWC; // attr->global attr->poolingMode = schema::PoolMode_MAX_POOLING; @@ -40,6 +42,7 @@ STATUS TfliteMaxPoolingParser::Parse(const std::unique_ptr &t attr->strideW = tflite_attr->stride_w; attr->strideH = tflite_attr->stride_h; attr->padMode = GetPadMode(tflite_attr->padding); + // calculate pad params if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc index caaf43a09f..9a8e490c45 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc @@ -27,13 +27,14 @@ STATUS TfliteMeanParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteMeanParser"; std::unique_ptr attr(new schema::MeanT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_ERROR; + return RET_NULL_PTR; } - attr->keepDims = tflite_attr->keep_dims; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axis)) { MS_LOG(ERROR) << "Mean get axis attr failed"; return RET_ERROR; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc index 2ec3e0221f..ec34e12bb4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc @@ -27,18 +27,22 @@ STATUS TfliteMeanPoolingParser::Parse(const std::unique_ptr & schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parser TfliteMeanPoolingParser"; std::unique_ptr attr(new schema::PoolingT()); + 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->format = schema::Format_NHWC; - // attr->global - attr->poolingMode = schema::PoolMode_MEAN_POOLING; 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_NHWC; + // attr->global + attr->poolingMode = schema::PoolMode_MEAN_POOLING; + // calculate pad params if (op != nullptr) { 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 eebe4941f5..1a7ce0c399 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc @@ -211,12 +211,18 @@ MetaGraphT *TfliteModelParser::Parse(const std::string &modelFile, const std::st // MS_LOGE("INPUT ILLEGAL: modelFile must be *.tflite"); return nullptr; } + + MS_LOG(INFO) << "modelFile is :" << modelFile; + std::unique_ptr tflite_model(new tflite::ModelT()); tflite_model = ReadTfliteModelFromFlat(modelFile.c_str()); if (tflite_model == nullptr) { // MS_LOGE("read tflite model failed"); return nullptr; } + + MS_LOG(INFO) << "after read model"; + TensorCache tensorCache; if (tflite_model->subgraphs.size() != 1) { MS_LOG(ERROR) << "read tflite model subgraphs failed"; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc index efdefbc743..8c2d3e9a94 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc @@ -29,21 +29,52 @@ STATUS TfliteMulParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteMulParser"; std::unique_ptr attr(new schema::MulT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsMulOptions(); - if (tfliteAttr == nullptr) { + 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); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; + } + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Mul; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc index 54167499b6..6e1c7e32d4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc @@ -86,6 +86,29 @@ STATUS TfliteNodeParser::ParseBias(const std::vector &bias_te return RET_OK; } +STATUS TfliteNodeParser::ParseTensor(const std::vector &ts, + const std::vector> &tfliteModelBuffer, + mindspore::lite::TensorCache *tensor_cache, int node_type, + bool ifCopy) { + for (const auto &t : ts) { + auto idx = tensor_cache->FindTensor(t->name); + if (idx < 0) { + std::unique_ptr tensor(new schema::TensorT); + tensor->dataType = GetTfliteDataType(t->type); + tensor->dims = t->shape; + + // memcpy tensor data, buffer is 0 (which refers to an always existent empty buffer) + if (ifCopy && t->buffer > 0) { + CopyTfliteTensorData(tfliteModelBuffer, t, tensor.get()); + } + + MS_LOG(DEBUG) << "add weight tensor name: %s", t->name.c_str(); + tensor_cache->AddTensor(t->name, tensor.release(), node_type); + } + } + return RET_OK; +} + TypeId TfliteNodeParser::GetTfliteDataType(const tflite::TensorType &tflite_data_type) { static std::unordered_map type_map = { {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, 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 3eeea81f83..4f8c0d7c05 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h @@ -49,9 +49,10 @@ class TfliteNodeParser { STATUS ParseBias(const std::vector &weight_tenosr, const std::vector> &tfliteModelBuffer, TensorCache *tensor_cache); - STATUS ParseAttr(const std::vector &attr_tenosrs, - const std::vector> &tfliteModelBuffer, - mindspore::lite::TensorCache *tensor_cache, schema::Format format); + STATUS ParseTensor(const std::vector &ts, + const std::vector> &tfliteModelBuffer, + mindspore::lite::TensorCache *tensor_cache, int node_type, + bool ifCopy); STATUS CopyTfliteTensorData(const std::vector> &tfliteModelBuffer, const tflite::TensorT *tflite_tensor, schema::TensorT *tensor); 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 8694a71840..9ecf8e7b07 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 @@ -27,13 +27,20 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr &tflit schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteOneHotParser"; std::unique_ptr attr(new schema::OneHotT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsOneHotOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + auto axis = tflite_attr->axis; - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + const auto &tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + const auto tensor_shape = tensor->shape; if (axis < 0) { axis += tensor_shape.size(); } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc index 92ec67de8f..169aa9d65b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc @@ -28,10 +28,12 @@ STATUS TflitePreluParser::Parse(const std::unique_ptr &tflite schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "paser TflitePreluParser"; std::unique_ptr attr(new schema::PreluT()); + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->slope)) { - MS_LOG(ERROR) << "pRelu -> slope get failed"; + MS_LOG(ERROR) << "get pRelu -> slope failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Prelu; 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 a49e032894..6bbadb7f6f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc @@ -30,15 +30,15 @@ STATUS TflitePadParser::Parse(const std::unique_ptr &tfliteOp const auto &tflite_attr = tfliteOp->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; - if (tfliteOp->inputs.size() > 1) { - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->paddings)) { - return RET_ERROR; - } + attr->constantValue = 0.0f; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->paddings)) { + MS_LOG(ERROR) << "get pad -> paddings failed"; + return RET_ERROR; } - // attr->constantValue = 0.0f; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc index aac929ff7a..a21986123d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc @@ -29,14 +29,9 @@ STATUS TflitePowParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TflitePowParser"; std::unique_ptr attr(new schema::PowerT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsPowOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - // the following use default values. This op is doing... attr->power = 0.0f; - attr->scale = 0.0f; + attr->scale = 1.0f; attr->shift = 0.0f; if (op != nullptr) { 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 ee7e66d2db..4f8330c7bc 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc @@ -29,34 +29,8 @@ STATUS TfliteRangeParser::Parse(const std::unique_ptr &tflite bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteRangeParser"; std::unique_ptr attr(new schema::RangeT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsRangeOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - auto start_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[start_idx]->shape.begin(), tfliteTensors[start_idx]->shape.end(), [&](int32_t sha){}); - auto &start_buf_data = tfliteModelBuffer[tfliteTensors[start_idx]->buffer]; - auto start_data_ptr = start_buf_data->data.data(); - attr->start = *(static_cast(static_cast(start_data_ptr))); - - auto limit_idx = tfliteOp->inputs[2]; - std::for_each(tfliteTensors[limit_idx]->shape.begin(), tfliteTensors[limit_idx]->shape.end(), [&](int32_t sha){}); - auto &limit_buf_data = tfliteModelBuffer[tfliteTensors[limit_idx]->buffer]; - auto limit_data_ptr = limit_buf_data->data.data(); - attr->limit = *(static_cast(static_cast(limit_data_ptr))); - - if (tfliteOp->inputs.size() > 2) { - auto delta_idx = tfliteOp->inputs[3]; - std::for_each(tfliteTensors[delta_idx]->shape.begin(), tfliteTensors[delta_idx]->shape.end(), [&](int32_t sha){}); - auto &delta_buf_data = tfliteModelBuffer[tfliteTensors[delta_idx]->buffer]; - auto delta_data_ptr = delta_buf_data->data.data(); - attr->delta = *(static_cast(static_cast(delta_data_ptr))); - } else { - attr->delta = 0; // default - } - attr->dType = 0; // default + attr->dType = 0; if (op != nullptr) { op->primitive = std::make_unique(); 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 bb64242230..002071d3e4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc @@ -29,10 +29,6 @@ STATUS TfliteRankParser::Parse(const std::unique_ptr &tfliteO bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteRankParser"; std::unique_ptr attr(new schema::RankT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsRankOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc index 10f6489575..98fae8209a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc @@ -32,15 +32,17 @@ STATUS TfliteReduceAnyParser::Parse(const std::unique_ptr &tf MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + + attr->keepDims = tflite_attr->keep_dims; // attr->mode = schema::; MS_LOG(ERROR) << "ms-lite haven't supported REDUCE_ANY now"; return RET_NOT_FIND_OP; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_ANY get axes attr failed"; + MS_LOG(ERROR) << "get reduce_any->axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc index 85e9dc70d6..a7bf6ef101 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc @@ -32,12 +32,14 @@ STATUS TfliteReduceMaxParser::Parse(const std::unique_ptr &tf MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->mode = schema::ReduceMode_ReduceMax; + attr->keepDims = tflite_attr->keep_dims; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_MAX get axes attr failed"; + MS_LOG(ERROR) << "get reduce_max -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc index 5c385b43a4..6185b208ab 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc @@ -32,12 +32,14 @@ STATUS TfliteReduceMinParser::Parse(const std::unique_ptr &tf MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->mode = schema::ReduceMode_ReduceMin; + attr->keepDims = tflite_attr->keep_dims; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_MIN get axes attr failed"; + MS_LOG(ERROR) << "get reduce_min -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc index 4d40540bf8..457fcbd2a7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc @@ -32,12 +32,14 @@ STATUS TfliteReduceProdParser::Parse(const std::unique_ptr &t MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + attr->mode = schema::ReduceMode_ReduceProd; + attr->keepDims = tflite_attr->keep_dims; if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_PROD get axes attr failed"; + MS_LOG(ERROR) << "get reduce_prod -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc index 657c3eaf17..05106948f1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc @@ -27,6 +27,7 @@ STATUS TfliteRelu6Parser::Parse(const std::unique_ptr &tflite schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteRelu6Parser"; std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_RELU6; if (op != nullptr) { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc index 31877c8d8f..467cbe9714 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc @@ -27,6 +27,7 @@ STATUS TfliteReluParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteReluParser"; std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_RELU; if (op != nullptr) { 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 968989f0c2..9fdf2ba11c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc @@ -37,6 +37,10 @@ STATUS TfliteReshapeParser::Parse(const std::unique_ptr &tfli } auto shape_tensor_index = tfliteOp->inputs[1]; const auto & shape_tensor = tfliteTensors[shape_tensor_index]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } std::vector shape_tensors{shape_tensor.get()}; if (RET_OK != ParseWeight(shape_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse shape tensor error"; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc index 13c7eb48c1..4c86861de2 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc @@ -27,23 +27,35 @@ STATUS TfliteResizeBilinearParser::Parse(const std::unique_ptr attr(new schema::ResizeT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeBilinearOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->alignCorners = tfliteAttr->align_corners; attr->format = schema::Format_NHWC; attr->method = schema::ResizeMethod_BILINEAR; - attr->alignCorners = tfliteAttr->align_corners; + attr->preserveAspectRatio = false; + auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; - auto resizeTensorBufferIndex = tfliteTensors.at(tfliteResizeTensorIndex)->buffer; - auto buffData = reinterpret_cast(tfliteModelBuffer.at(resizeTensorBufferIndex)->data.data()); + const auto & shape_tensor = tfliteTensors[tfliteResizeTensorIndex]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + auto resizeTensorBufferIndex = shape_tensor->buffer; + const auto & buff = tfliteModelBuffer.at(resizeTensorBufferIndex); + if (buff == nullptr) { + MS_LOG(ERROR) << "buff_data is null"; + return RET_NULL_PTR; + } + auto buffData = reinterpret_cast(buff->data.data()); auto height = buffData[0]; auto width = buffData[1]; attr->newWidth = width; attr->newHeight = height; - // attr->preserveAspectRatio if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc index 20438d63a4..384e419f50 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc @@ -27,23 +27,35 @@ STATUS TfliteResizeNearestNeighborParser::Parse(const std::unique_ptr attr(new schema::ResizeT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeNearestNeighborOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } + attr->alignCorners = tfliteAttr->align_corners; attr->format = schema::Format_NHWC; attr->method = schema::ResizeMethod_NEAREST_NEIGHBOR; - attr->alignCorners = tfliteAttr->align_corners; + attr->preserveAspectRatio = false; + auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; - auto resizeTensorBufferIndex = tfliteTensors.at(tfliteResizeTensorIndex)->buffer; - auto buffData = reinterpret_cast(tfliteModelBuffer.at(resizeTensorBufferIndex)->data.data()); + const auto & shape_tensor = tfliteTensors[tfliteResizeTensorIndex]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + auto resizeTensorBufferIndex = shape_tensor->buffer; + const auto & buff = tfliteModelBuffer.at(resizeTensorBufferIndex); + if (buff == nullptr) { + MS_LOG(ERROR) << "buff_data is null"; + return RET_NULL_PTR; + } + auto buffData = reinterpret_cast(buff->data.data()); auto height = buffData[0]; auto width = buffData[1]; attr->newWidth = width; attr->newHeight = height; - // attr->preserveAspectRatio if (op != nullptr) { op->primitive = std::make_unique(); 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 f516d7e2d1..8f5f368f8f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc @@ -29,11 +29,6 @@ STATUS TfliteReverseParser::Parse(const std::unique_ptr &tfli bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteReverseParser"; std::unique_ptr attr(new schema::ReverseT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsReverseV2Options(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axis)) { return RET_ERROR; @@ -47,7 +42,7 @@ STATUS TfliteReverseParser::Parse(const std::unique_ptr &tfli return RET_OK; } -TfliteNodeRegister g_tfliteReverseParser("Reverse", new TfliteReverseParser()); +TfliteNodeRegister g_tfliteReverseParser("reverse", new TfliteReverseParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h index 1db4301566..3965ab1ece 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteReverseParser : public TfliteNodeParser { public: - TfliteReverseParser() : TfliteNodeParser("Reverse") {} + TfliteReverseParser() : TfliteNodeParser("reverse") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, 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 3658541d98..7dcedbc168 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 @@ -29,13 +29,20 @@ STATUS TfliteReverseSequenceParser::Parse(const std::unique_ptr attr(new schema::ReverseSequenceT()); - const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions(); + 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; + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->seqLengths)) { + MS_LOG(ERROR) << "get reverse_sequence -> seqLengths failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ReverseSequence; 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 a113266496..62108b8a17 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 @@ -28,6 +28,7 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr &tf schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteScatterNdParser"; std::unique_ptr attr(new schema::ScatterNDT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsScatterNdOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; 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 eab6694a7a..ac545ccceb 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc @@ -28,8 +28,6 @@ STATUS TfliteShapeParser::Parse(const std::unique_ptr &tflite MS_LOG(INFO) << "parse TfliteShapeParser"; std::unique_ptr attr(new schema::ShapeT()); - // tflite_attr->out_type; // this attr is dropped - if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Shape; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc deleted file mode 100644 index fcfe4110d1..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_sigmoid_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSigmoidParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteSigmoidParser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_SIGMOID; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSigmoidParser("Sigmoid", new TfliteSigmoidParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h deleted file mode 100644 index f291125964..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PREDICT_TFLITE_SIGMOID_PARSER_H -#define PREDICT_TFLITE_SIGMOID_PARSER_H - -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -#include -#include - -namespace mindspore { -namespace lite { -class TfliteSigmoidParser : public TfliteNodeParser { - public: - TfliteSigmoidParser() : TfliteNodeParser("Sigmoid") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SIGMOID_PARSER_H - 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 9f74bddd8f..ced928e48e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc @@ -30,9 +30,11 @@ STATUS TfliteSliceParser::Parse(const std::unique_ptr &tflite std::unique_ptr attr(new schema::SliceT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->begin)) { + MS_LOG(ERROR) << "get slice -> begin failed"; return RET_ERROR; } if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->size)) { + MS_LOG(ERROR) << "get slice -> size failed"; return RET_ERROR; } 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 07bb3a9507..9680de53a0 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc @@ -28,11 +28,14 @@ STATUS TfliteSoftmaxParser::Parse(const std::unique_ptr &tfli TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteSoftmaxParser"; std::unique_ptr attr(new schema::SoftMaxT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSoftmaxOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - // attr->axis + + attr->axis = -1; if (op != nullptr) { op->primitive = std::make_unique(); 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 ea3c2c8a3f..427e775bd2 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 @@ -29,12 +29,13 @@ STATUS TfliteSpaceToBatchNDParser::Parse(const std::unique_ptr attr(new schema::SpaceToBatchNDT()); + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) { - MS_LOG(ERROR) << "spaceToBatchND -> blockShape get failed"; + MS_LOG(ERROR) << "get spaceToBatchND -> blockShape failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->paddings)) { - MS_LOG(ERROR) << "spaceToBatchND -> paddings get failed"; + MS_LOG(ERROR) << "get spaceToBatchND -> paddings failed"; return RET_ERROR; } 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 e3435bc5f3..afefcc8101 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 @@ -29,13 +29,14 @@ STATUS TfliteSpaceToDepthParser::Parse(const std::unique_ptr TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteSpaceToDepthParser"; std::unique_ptr attr(new schema::SpaceToDepthT()); + 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_NHWC; if (op != nullptr) { 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 86ed3d0a2a..f579574caf 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 @@ -30,19 +30,21 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr MS_LOG(DEBUG) << "parse TfliteSparseToDenseParser"; std::unique_ptr attr(new schema::SparseToDenseT()); + attr->validateIndices = false; + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->outputShape)) { - MS_LOG(ERROR) << "sparseToDense -> outputShape get failed"; + MS_LOG(ERROR) << "get sparseToDense -> outputShape failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->sparseValue)) { - MS_LOG(ERROR) << "sparseToDense -> sparseValue get failed"; + MS_LOG(ERROR) << "get sparseToDense -> sparseValue failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[3], tflite_tensors, tflite_model_buffer, attr->defaultValue)) { - MS_LOG(ERROR) << "sparseToDense -> defaultValue get failed"; + MS_LOG(ERROR) << "get sparseToDense -> defaultValue failed"; return RET_ERROR; } - attr->validateIndices = false; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_SparseToDense; 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 eeb5d7c226..946f81482d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc @@ -29,15 +29,26 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSplitParser"; std::unique_ptr attr(new schema::SplitT()); + const auto &tflite_attr = tfliteOp->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 tensor_shape = tfliteTensors[tfliteOp->inputs[1]].get()->shape; - auto axis = - *(reinterpret_cast(tfliteModelBuffer[tfliteTensors[tfliteOp->inputs[0]]->buffer]->data.data())); + const auto &shape_tensor = tfliteTensors[tfliteOp->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 = tfliteTensors[tfliteOp->inputs[0]]; + if (axis_tensor == nullptr) { + MS_LOG(ERROR) << "axis_tensor is null"; + return RET_NULL_PTR; + } + auto axis = *(reinterpret_cast(tfliteModelBuffer[axis_tensor->buffer]->data.data())); if (axis < 0) { axis += tensor_shape.size(); } @@ -46,8 +57,6 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite return RET_ERROR; } attr->splitDim = axis; - - auto num_splits = tflite_attr->num_splits; if (tensor_shape[axis] % num_splits != 0) { MS_LOG(ERROR) << "num_splits can't divide tensor's length at axis " << axis; return RET_ERROR; 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 938ce612c2..214e32617d 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 @@ -27,21 +27,31 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr &tflit schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSplitVParser"; std::unique_ptr attr(new schema::SplitT()); + const auto &tflite_attr = tfliteOp->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(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->sizeSplits)) { - MS_LOG(ERROR) << "SPLIT_V get sizeSplits attr failed"; + MS_LOG(ERROR) << "get splite_v -> sizeSplits failed"; return RET_ERROR; } - auto axis = - *(reinterpret_cast(tfliteModelBuffer[tfliteTensors[tfliteOp->inputs[2]]->buffer]->data.data())); - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + const auto &tensor = tfliteTensors[tfliteOp->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 = tfliteTensors[tfliteOp->inputs[2]]; + if (axis_tensor == nullptr) { + MS_LOG(ERROR) << "axis_tensor is null"; + return RET_NULL_PTR; + } + auto axis = *(reinterpret_cast(tfliteModelBuffer[axis_tensor->buffer]->data.data())); if (axis < 0) { axis += tensor_shape.size(); } @@ -49,6 +59,7 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr &tflit MS_LOG(ERROR) << "axis value too large"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Split; 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 932acb90b0..521793c7f3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc @@ -27,12 +27,12 @@ STATUS TfliteSqueezeParser::Parse(const std::unique_ptr &tfli schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSqueezeParser"; std::unique_ptr attr(new schema::SqueezeT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSqueezeOptions(); if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } - attr->axis = tflite_attr->squeeze_dims; if (op != nullptr) { 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 43d76b3c56..13dbb78375 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc @@ -30,6 +30,7 @@ STATUS TfliteStackParser::Parse(const std::unique_ptr &tflite const auto &tflite_attr = tfliteOp->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; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc index 1a517f1490..4748e83983 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc @@ -29,18 +29,52 @@ STATUS TfliteSubParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteSubParser"; std::unique_ptr attr(new schema::SubT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsSubOptions(); - if (tfliteAttr == nullptr) { + 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); - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (x_data->data.size() > 0) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (y_data->data.size() > 0) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST, true)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Sub; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc index 9844d45467..0ee5fb7ce3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc @@ -27,18 +27,20 @@ STATUS TfliteSumParser::Parse(const std::unique_ptr &tfliteOp schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteSumParser"; std::unique_ptr attr(new schema::ReduceT()); + const auto &tflite_attr = tfliteOp->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; + attr->mode = schema::ReduceMode_ReduceSum; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "SUM get axes attr failed"; + MS_LOG(ERROR) << "get sum -> axes failed"; return RET_ERROR; } - attr->keepDims = tflite_attr->keep_dims; - if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Reduce; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc index f78b8fa71e..1991cfad01 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc @@ -27,6 +27,7 @@ STATUS TfliteTanhParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteTanhParser"; std::unique_ptr attr(new schema::ActivationT()); + attr->type = schema::ActivationType_TANH; if (op != nullptr) { 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 c3e259fa27..b0ce2de061 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc @@ -31,7 +31,7 @@ STATUS TfliteTileParser::Parse(const std::unique_ptr &tflite_ std::unique_ptr attr(new schema::TileT()); if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->multiples)) { - MS_LOG(ERROR) << "tile -> multiples get failed"; + MS_LOG(ERROR) << "get tile -> multiples failed"; return RET_ERROR; } 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 c086eab7d4..a9c285ace1 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 @@ -31,9 +31,10 @@ STATUS TfliteTopKV2Parser::Parse(const std::unique_ptr &tflit std::unique_ptr attr(new schema::TopKV2T()); if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->k)) { - MS_LOG(ERROR) << "topKV2 -> k get failed"; + MS_LOG(ERROR) << "get topKV2 -> k failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_TopKV2; 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 829a813701..349dd921a0 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc @@ -29,12 +29,16 @@ STATUS TfliteTransposeParser::Parse(const std::unique_ptr &tf std::unique_ptr attr(new schema::TransposeT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->perm)) { - MS_LOG(ERROR) << "parse Transpose attr perm failed"; + MS_LOG(ERROR) << "get transpose -> perm failed"; return RET_ERROR; } auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_ERROR; + } std::vector weight_tensors{weight_tensor.get()}; if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse weight failed"; 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 12131d606f..70405ec766 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc @@ -29,6 +29,7 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteUniqueParser"; std::unique_ptr attr(new schema::UniqueT()); + 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(); @@ -36,6 +37,7 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit } attr->outType = dtype_map[tflite_attr->idx_out_type]; + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Unique; 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 eca413ba7a..dc94140e32 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc @@ -28,12 +28,12 @@ STATUS TfliteUnstackParser::Parse(const std::unique_ptr &tfli schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "paser TfliteUnstackParser"; std::unique_ptr attr(new schema::UnstackT()); + 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; 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 e05e7cb507..0476a4ab32 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc @@ -31,9 +31,10 @@ STATUS TfliteWhereParser::Parse(const std::unique_ptr &tflite std::unique_ptr attr(new schema::WhereT()); if (GetTfliteData(tflite_op->inputs[0], tflite_tensors, tflite_model_buffer, attr->condition)) { - MS_LOG(ERROR) << "where -> condition get failed"; + MS_LOG(ERROR) << "get where -> condition failed"; return RET_ERROR; } + if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Where;