diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 6c09c96f4dc83f88150ec113069c27a9aeb31f27..c9ff6db684a80145b747bc8eb04ab88a5580fe90 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -191,8 +191,12 @@ if (SUPPORT_GPU) endif() ### converter if(BUILD_CONVERTER) + file(GLOB_RECURSE TEST_CASE_TFLITE_PARSERS_SRC + ${TEST_DIR}/ut/tools/converter/parser/tflite/*.cc + ) set(TEST_LITE_SRC ${TEST_LITE_SRC} + ${TEST_CASE_TFLITE_PARSERS_SRC} ${TOP_DIR}/mindspore/core/utils/flags.cc ${LITE_DIR}/tools/converter/optimizer.cc ${LITE_DIR}/src/common/anf_importer/anf_importer.cc diff --git a/mindspore/lite/test/run_test.sh b/mindspore/lite/test/run_test.sh index 4571fae6e725279db1894fe84da68aa437b77dc7..adfb48130f0854f20a4eb6ef22f13b18b89f77c7 100755 --- a/mindspore/lite/test/run_test.sh +++ b/mindspore/lite/test/run_test.sh @@ -7,6 +7,7 @@ mkdir -pv ${CUR_DIR}/do_test cd ${CUR_DIR}/do_test cp ${BUILD_DIR}/test/lite-test ./ cp -r ${CUR_DIR}/ut/src/runtime/kernel/arm/test_data/* ./ +cp -r ${CUR_DIR}/ut/tools/converter/parser/tflite/test_data/* ./ ## prepare data for dataset TEST_DATA_DIR=${CUR_DIR}/../../../tests/ut/data/dataset/ cp -fr $TEST_DATA_DIR/testPK ./data @@ -14,6 +15,8 @@ cp -fr $TEST_DATA_DIR/testPK ./data ./lite-test --gtest_filter="*MindDataTestTensorDE*" ./lite-test --gtest_filter="*MindDataTestEager*" +./lite-test --gtest_filter="TestTfliteParser*" + ./lite-test --gtest_filter="*TestHebing*" ./lite-test --gtest_filter=TestFcFp32* diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite new file mode 100644 index 0000000000000000000000000000000000000000..29768a273ad18e29c0626c0b1f912b7643937d93 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite new file mode 100644 index 0000000000000000000000000000000000000000..87f8e477c38ffb45eb1865231e834e7a8f25924f Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cos.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cos.tflite new file mode 100644 index 0000000000000000000000000000000000000000..2f90af40927e271d0ff919a33382c0a76aaa07fb Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cos.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/test_data/tflite_exp_model/Exp.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite similarity index 100% rename from mindspore/lite/test/ut/tools/converter/parser/test_data/tflite_exp_model/Exp.tflite rename to mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite new file mode 100644 index 0000000000000000000000000000000000000000..734fa6e775a35f90bfd118e61381ccca23c5af41 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite new file mode 100644 index 0000000000000000000000000000000000000000..a26b1bebf086d63662d44b0b4e81298e3892b641 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_not.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_not.tflite new file mode 100644 index 0000000000000000000000000000000000000000..9cbbe05d4487305cd482f7e784abc7e3d30874b3 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_not.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite new file mode 100644 index 0000000000000000000000000000000000000000..ac539be1b78999e777a873f6e40f340e797a250b Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/maximum.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/maximum.tflite new file mode 100644 index 0000000000000000000000000000000000000000..3d3b6a3eef798e6cb2825ecadd32e83c51df3dcd Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/maximum.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite new file mode 100644 index 0000000000000000000000000000000000000000..691b3c25d633a2723caf031704a3faf057c34d3c Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite new file mode 100644 index 0000000000000000000000000000000000000000..3e81d98f450bc25490862967369a7ad9f3e81a5e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite new file mode 100644 index 0000000000000000000000000000000000000000..96fde48b3a143d1b897bdfd88e97d954fd2d3ece Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_min.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_min.tflite new file mode 100644 index 0000000000000000000000000000000000000000..e60aaf4756241fd477de45c915e9677c3409980f Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_min.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite new file mode 100644 index 0000000000000000000000000000000000000000..7eaa9f4f24f28793895b07b34e7af167da2388d7 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite new file mode 100644 index 0000000000000000000000000000000000000000..6275509186137ff51f45070f33caac27e5206219 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite new file mode 100644 index 0000000000000000000000000000000000000000..a06748d47c2a38d4ff5050960f0b267a680dd28b Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split.tflite new file mode 100644 index 0000000000000000000000000000000000000000..def7d53523483d06321eb08d47a9ad2d4b4143ca Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite new file mode 100644 index 0000000000000000000000000000000000000000..61405534dca0c64228d7e2cfad76d3d420cf3d13 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite new file mode 100644 index 0000000000000000000000000000000000000000..984f61353de65b256a75607e10c9aa08598333ca Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite new file mode 100644 index 0000000000000000000000000000000000000000..8bd23c38c7eda6abecf226bb9a8bbacdd9616d85 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sum.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sum.tflite new file mode 100644 index 0000000000000000000000000000000000000000..d84b2fedbc1d666c0f57fed8ecbac4d2a1ece045 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sum.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 new file mode 100644 index 0000000000000000000000000000000000000000..c90ff924a14e8e7c27ec43dd97ce6f032ddaea95 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserAbs : public TestTfliteParser { + public: + TestTfliteParserAbs() {} + void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } +}; + +TEST_F(TestTfliteParserAbs, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Abs) << "wrong Op Type"; +} + +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..4d37fa506a6d7acd555147083b50a718824e3da3 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserBatchToSpaceNd : public TestTfliteParser { + public: + TestTfliteParserBatchToSpaceNd() {} + void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } +}; + +TEST_F(TestTfliteParserBatchToSpaceNd, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_BatchToSpace) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserBatchToSpaceNd, AttrValue) { + const std::vector<int> blockShape{2, 2}; + const std::vector<int> crops{0, 0, 2, 0}; + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsBatchToSpace(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsBatchToSpace()->blockShape, blockShape); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsBatchToSpace()->crops, crops); +} + +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..785cd35e444be05076944076d6bfb622c1fe90ed --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserCos : public TestTfliteParser { + public: + TestTfliteParserCos() {} + void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } +}; + +TEST_F(TestTfliteParserCos, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Cos) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc index eec816f2a33b182d1a1931970e1181ca164d39d1..5a09b9e42809b3606b3ff9ae7f2951940447de29 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc @@ -13,31 +13,22 @@ * 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 <iostream> -#include "mindspore/core/utils/log_adapter.h" #include "common/common_test.h" -#include "tools/converter/converter_flags.h" -#include "schema/inner/model_generated.h" -#include "tools/converter/parser/tflite/tflite_converter.h" -#include "tools/converter/parser/tflite/tflite_exp_parser.h" -#include "src/kernel_registry.h" -#include "src/lite_kernel.h" namespace mindspore { - -class TestTfliteExpParser : public mindspore::Common { +class TestTfliteParserExp : public TestTfliteParser { public: - TestTfliteExpParser() {} + TestTfliteParserExp() {} + void SetUp() override { meta_graph = LoadAndConvert("./exp.tflite", ""); } }; -TEST_F(TestTfliteExpParser, ExpParser) { - lite::converter::Flags flags; - flags.modelFile = "./test_data/Exp.tflite"; - flags.fmk = lite::converter::FmkType_TFLITE; - lite::TfliteConverter converter; - schema::MetaGraphT *fb_graph = nullptr; - fb_graph = converter.Convert(&flags); - const auto &nodes = fb_graph->nodes; - nodes.back(); +TEST_F(TestTfliteParserExp, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Exp) << "wrong Op Type"; } + } // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..fe869019cefcfe157be267d0de6fd439408c6b76 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLog : public TestTfliteParser { + public: + TestTfliteParserLog() {} + void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } +}; + +TEST_F(TestTfliteParserLog, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Log) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..415dc874ee9d1d9e627c1b1bf71c0a066a2bab1b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteLogicalParserAnd : public TestTfliteParser { + public: + TestTfliteLogicalParserAnd() {} + void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } +}; + +TEST_F(TestTfliteLogicalParserAnd, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_LogicalAnd) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..a34ae07afea5780e4a7f093cd2ff644aa25e7e86 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLogicalNot : public TestTfliteParser { + public: + TestTfliteParserLogicalNot() {} + void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } +}; + +TEST_F(TestTfliteParserLogicalNot, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_LogicalNot) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..19141d61250c12c56d13953755309093d3a25e8e --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLogicalOr : public TestTfliteParser { + public: + TestTfliteParserLogicalOr() {} + void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } +}; + +TEST_F(TestTfliteParserLogicalOr, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_LogicalOr) << "wrong Op Type"; +} + +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..a21dba4d8bb02006b7380272ae2b9e228a332680 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserMaximum : public TestTfliteParser { + public: + TestTfliteParserMaximum() {} + void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } +}; + +TEST_F(TestTfliteParserMaximum, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Maximum) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..2999d33b16d7631ef7d4730625622586d3817def --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserMinimum : public TestTfliteParser { + public: + TestTfliteParserMinimum() {} + void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } +}; + +TEST_F(TestTfliteParserMinimum, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Minimum) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..f1f007e849aa24c9e2cba31e5dccaa003b6191ce --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserOneHot : public TestTfliteParser { + public: + TestTfliteParserOneHot() {} + void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } +}; + +TEST_F(TestTfliteParserOneHot, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_OneHot) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserOneHot, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsOneHot(), nullptr); + // in OneHot parser axis = axis > 0 ? axis : axis + tensor_shape.size() + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsOneHot()->axis, 2); +} + +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..881d95b89ff6c6e4a7ac5a8aafc4f82e195ca56f --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.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 <string> +#include "schema/inner/model_generated.h" +#include "tools/converter/parser/tflite/tflite_model_parser.h" + +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); + return meta_graph; +} + +void TestTfliteParser::TearDown() { free(meta_graph); } + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..cf592570c3f86a1af5bb48cf28b7343eb2b6fec2 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h @@ -0,0 +1,35 @@ +/** + * 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 MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_ +#define MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_ + +#include <string> +#include "common/common_test.h" +#include "schema/inner/model_generated.h" + +namespace mindspore { +class TestTfliteParser : public Common { + public: + TestTfliteParser() {} + void TearDown() override; + schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); + schema::MetaGraphT *meta_graph; +}; + +} // namespace mindspore + +#endif // MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_ 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 new file mode 100644 index 0000000000000000000000000000000000000000..6c2ff5711457c6658ea44d18fe5d5bf4981dea11 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReduceMax : public TestTfliteParser { + public: + TestTfliteParserReduceMax() {} + void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } +}; + +TEST_F(TestTfliteParserReduceMax, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReduceMax, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceMax) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..dce6a95fb049d2e652cca9174cced250efd3bff2 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReduceMin : public TestTfliteParser { + public: + TestTfliteParserReduceMin() {} + void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } +}; + +TEST_F(TestTfliteParserReduceMin, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReduceMin, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceMin) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..dc19ad983faadf59b70b62752be2c3ee8e30ce74 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReduceProd : public TestTfliteParser { + public: + TestTfliteParserReduceProd() {} + void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } +}; + +TEST_F(TestTfliteParserReduceProd, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReduceProd, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceProd) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..c1db7380cb812a8e7b093126c22be831d5b1a584 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserRsqrt : public TestTfliteParser { + public: + TestTfliteParserRsqrt() {} + void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } +}; + +TEST_F(TestTfliteParserRsqrt, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Rsqrt) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..a859cabc87b83bca37d29763ea11e6ea23c4a90d --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSin : public TestTfliteParser { + public: + TestTfliteParserSin() {} + void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } +}; + +TEST_F(TestTfliteParserSin, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Sin) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..aae2b629d137788e3879681629c3bcd4a478f8cc --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSplit : public TestTfliteParser { + public: + TestTfliteParserSplit() {} + + void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } +}; + +TEST_F(TestTfliteParserSplit, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Split) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSplit, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsSplit(), nullptr); + const std::vector<int> sizeSplits{2, 2}; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->splitDim, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->numberSplit, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->sizeSplits, sizeSplits); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..30a7049a425695c38d923f790cb801888b867764 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc @@ -0,0 +1,46 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSplitV : public TestTfliteParser { + public: + TestTfliteParserSplitV() {} + + void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } +}; + +TEST_F(TestTfliteParserSplitV, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Split) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSplitV, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsSplit(), nullptr); + const std::vector<int> sizeSplits{1, 3}; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->splitDim, 0); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->numberSplit, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->sizeSplits, sizeSplits); +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..427907dc70c4eb3d18e3bb12cf6e84f2569d28cf --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSqrt : public TestTfliteParser { + public: + TestTfliteParserSqrt() {} + void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } +}; + +TEST_F(TestTfliteParserSqrt, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Sqrt) << "wrong Op Type"; +} + +} // namespace mindspore 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 new file mode 100644 index 0000000000000000000000000000000000000000..5301c2302ae8e96ac4cfc77549811a19cf400178 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc @@ -0,0 +1,34 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSquare : public TestTfliteParser { + public: + TestTfliteParserSquare() {} + void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } +}; + +TEST_F(TestTfliteParserSquare, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Square) << "wrong Op Type"; +} + +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..f028516da2367cd141a35dedf1658f6a0701adc2 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc @@ -0,0 +1,47 @@ +/** + * 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 <iostream> +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSum : public TestTfliteParser { + public: + TestTfliteParserSum() {} + + void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } +}; + +TEST_F(TestTfliteParserSum, OpType) { + ASSERT_NE(meta_graph, nullptr); + 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_Reduce) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSum, AttrValue) { + ASSERT_NE(meta_graph, nullptr); + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceSum) + << "wrong reduce mode"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2); +} + +} // namespace mindspore 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 a7f12d9e171ce7038b487a189b14a8bae616813e..6ed52bfb12e62477fdffb7e28983e163031077cb 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 @@ -24,12 +24,13 @@ STATUS TfliteBatchToSpaceNDParser::Parse(const std::unique_ptr<tflite::OperatorT const std::vector<std::unique_ptr<tflite::TensorT>> &tfliteTensors, const std::vector<std::unique_ptr<tflite::BufferT>> &tfliteModelBuffer, const std::vector<std::unique_ptr<tflite::OperatorCodeT>> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { MS_LOG(INFO) << "parse TfliteBatchToSpaceNDParser"; std::unique_ptr<schema::BatchToSpaceT> attr(new schema::BatchToSpaceT()); + // in tflite + // blockShape should be a 1D tensor with dimension [spatial_dims_num] + // crops should be a 2D tensor with dimension [spatial_dims_num, 2] if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed"; return RET_ERROR; 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 57660c1fb8b9686ef4ab49d6841d98fc5331c778..8694a71840617e05162d17c8cbbf615026a68a13 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 @@ -32,8 +32,12 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } - - attr->axis = tflite_attr->axis; + auto axis = tflite_attr->axis; + const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + if (axis < 0) { + axis += tensor_shape.size(); + } + attr->axis = axis; if (op != nullptr) { op->primitive = std::make_unique<schema::PrimitiveT>(); 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 f416db2e5e7e4e14ab6ab9ae54f2a02544dada38..a1132664966c6793eccb87d21a1eda8c07cc775f 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 @@ -39,6 +39,8 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf MS_LOG(DEBUG) << i; } */ + // in tflite, kIndices = 0, kUpdates = 1, kShape = 2 + // in mslite, kScatterShapeIndex = 0, kScatterIndicesIndex = 1, kScatterUpdateIndex = 2; std::swap(op->inputIndex[0], op->inputIndex[2]); std::swap(op->inputIndex[1], op->inputIndex[2]); /* 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 b2d5f1246ec824c43d2dfe3bbfb5094eac3e3d01..eeb5d7c22686abfb34b178523f393d0a8ec23204 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc @@ -54,7 +54,7 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite } attr->numberSplit = num_splits; - for (int i = 0; i <= num_splits; i++) { + for (int i = 0; i < num_splits; i++) { attr->sizeSplits.push_back(tensor_shape[axis] / num_splits); }