supplement some tflite parser ut. format tflite parsers and uttags/v0.7.0-beta
| @@ -1,5 +1,7 @@ | |||||
| set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) | |||||
| set(TEST_DIR ${TOP_DIR}/mindspore/lite/test) | set(TEST_DIR ${TOP_DIR}/mindspore/lite/test) | ||||
| set(LITE_DIR ${TOP_DIR}/mindspore/lite) | set(LITE_DIR ${TOP_DIR}/mindspore/lite) | ||||
| set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc) | |||||
| include_directories(${TOP_DIR}) | include_directories(${TOP_DIR}) | ||||
| include_directories(${TEST_DIR}) | include_directories(${TEST_DIR}) | ||||
| include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake) | 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/base/base.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../core/utils/log_adapter.cc | ${CMAKE_CURRENT_SOURCE_DIR}/../../core/utils/log_adapter.cc | ||||
| ) | ) | ||||
| if(BUILD_CONVERTER) | if(BUILD_CONVERTER) | ||||
| set(ANF_SRC | set(ANF_SRC | ||||
| ${ANF_SRC} | ${ANF_SRC} | ||||
| @@ -26,3 +26,5 @@ cp -fr $TEST_DATA_DIR/testPK ./data | |||||
| ./lite-test --gtest_filter=TestPadInt8.* | ./lite-test --gtest_filter=TestPadInt8.* | ||||
| ./lite-test --gtest_filter=TestDeconvInt8.* | ./lite-test --gtest_filter=TestDeconvInt8.* | ||||
| ./lite-test --gtest_filter="TestTfliteParser*" | |||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserAbs : public TestTfliteParser { | class TestTfliteParserAbs : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserAbs() {} | |||||
| TestTfliteParserAbs() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserAddN : public TestTfliteParser { | class TestTfliteParserAddN : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserAddN() {} | |||||
| TestTfliteParserAddN() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./addn.tflite"); | meta_graph = LoadAndConvert("./addn.tflite"); | ||||
| } | } | ||||
| @@ -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 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 | |||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserBatchToSpaceNd : public TestTfliteParser { | class TestTfliteParserBatchToSpaceNd : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserBatchToSpaceNd() {} | |||||
| TestTfliteParserBatchToSpaceNd() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserCast : public TestTfliteParser { | class TestTfliteParserCast : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserCast() {} | |||||
| TestTfliteParserCast() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./cast.tflite"); | meta_graph = LoadAndConvert("./cast.tflite"); | ||||
| } | } | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserCos : public TestTfliteParser { | class TestTfliteParserCos : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserCos() {} | |||||
| TestTfliteParserCos() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserDepthToSpace : public TestTfliteParser { | class TestTfliteParserDepthToSpace : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserDepthToSpace() {} | |||||
| TestTfliteParserDepthToSpace() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./depth_to_space.tflite"); | meta_graph = LoadAndConvert("./depth_to_space.tflite"); | ||||
| } | } | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserEqual : public TestTfliteParser { | class TestTfliteParserEqual : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserEqual() {} | |||||
| TestTfliteParserEqual() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./equal.tflite"); | meta_graph = LoadAndConvert("./equal.tflite"); | ||||
| } | } | ||||
| @@ -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 <iostream> | |||||
| #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<int32_t> dims = {9}; | |||||
| ASSERT_EQ(val->dims, dims); | |||||
| } | |||||
| } // namespace mindspore | |||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserGreaterEqual : public TestTfliteParser { | class TestTfliteParserGreaterEqual : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserGreaterEqual() {} | |||||
| TestTfliteParserGreaterEqual() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./greater_equal.tflite"); | meta_graph = LoadAndConvert("./greater_equal.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserGreater : public TestTfliteParser { | class TestTfliteParserGreater : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserGreater() {} | |||||
| TestTfliteParserGreater() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./greater.tflite"); | meta_graph = LoadAndConvert("./greater.tflite"); | ||||
| } | } | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserLessEqual : public TestTfliteParser { | class TestTfliteParserLessEqual : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserLessEqual() {} | |||||
| TestTfliteParserLessEqual() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./less_equal.tflite"); | meta_graph = LoadAndConvert("./less_equal.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserLess : public TestTfliteParser { | class TestTfliteParserLess : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserLess() {} | |||||
| TestTfliteParserLess() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./less.tflite"); | meta_graph = LoadAndConvert("./less.tflite"); | ||||
| } | } | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserLog : public TestTfliteParser { | class TestTfliteParserLog : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserLog() {} | |||||
| TestTfliteParserLog() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteLogicalParserAnd : public TestTfliteParser { | class TestTfliteLogicalParserAnd : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteLogicalParserAnd() {} | |||||
| TestTfliteLogicalParserAnd() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserLogicalNot : public TestTfliteParser { | class TestTfliteParserLogicalNot : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserLogicalNot() {} | |||||
| TestTfliteParserLogicalNot() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserLogicalOr : public TestTfliteParser { | class TestTfliteParserLogicalOr : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserLogicalOr() {} | |||||
| TestTfliteParserLogicalOr() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -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 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 | |||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserMaximum : public TestTfliteParser { | class TestTfliteParserMaximum : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserMaximum() {} | |||||
| TestTfliteParserMaximum() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserMinimum : public TestTfliteParser { | class TestTfliteParserMinimum : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserMinimum() {} | |||||
| TestTfliteParserMinimum() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } | ||||
| }; | }; | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserNotEqual : public TestTfliteParser { | class TestTfliteParserNotEqual : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserNotEqual() {} | |||||
| TestTfliteParserNotEqual() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./not_equal.tflite"); | meta_graph = LoadAndConvert("./not_equal.tflite"); | ||||
| } | } | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserOneHot : public TestTfliteParser { | class TestTfliteParserOneHot : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserOneHot() {} | |||||
| TestTfliteParserOneHot() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserPrelu : public TestTfliteParser { | class TestTfliteParserPrelu : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserPrelu() {} | |||||
| TestTfliteParserPrelu() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./prelu.tflite"); | meta_graph = LoadAndConvert("./prelu.tflite"); | ||||
| } | } | ||||
| @@ -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 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<int32_t> paddings = {1, 1, 2, 2, 3, 3, 4, 4}; | |||||
| ASSERT_EQ(val->paddings, paddings); | |||||
| } | |||||
| } // namespace mindspore | |||||
| @@ -22,9 +22,12 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| schema::MetaGraphT *TestTfliteParser::LoadAndConvert(const string &model_path, const string &weight_path) { | schema::MetaGraphT *TestTfliteParser::LoadAndConvert(const string &model_path, const string &weight_path) { | ||||
| schema::MetaGraphT *meta_graph = nullptr; | |||||
| lite::TfliteModelParser parser; | lite::TfliteModelParser parser; | ||||
| meta_graph = parser.Parse(model_path, weight_path); | 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; | return meta_graph; | ||||
| } | } | ||||
| @@ -24,10 +24,10 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParser : public Common { | class TestTfliteParser : public Common { | ||||
| public: | public: | ||||
| TestTfliteParser() {} | |||||
| TestTfliteParser() = default; | |||||
| void TearDown() override; | void TearDown() override; | ||||
| schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); | schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); | ||||
| schema::MetaGraphT *meta_graph; | |||||
| schema::MetaGraphT *meta_graph = nullptr; | |||||
| }; | }; | ||||
| } // namespace mindspore | } // namespace mindspore | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserReduceMax : public TestTfliteParser { | class TestTfliteParserReduceMax : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserReduceMax() {} | |||||
| TestTfliteParserReduceMax() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserReduceMin : public TestTfliteParser { | class TestTfliteParserReduceMin : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserReduceMin() {} | |||||
| TestTfliteParserReduceMin() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserReduceProd : public TestTfliteParser { | class TestTfliteParserReduceProd : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserReduceProd() {} | |||||
| TestTfliteParserReduceProd() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } | ||||
| }; | }; | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -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 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<int32_t> axis = {3}; | |||||
| ASSERT_EQ(val->axis, axis); | |||||
| } | |||||
| } // namespace mindspore | |||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserReverseSequence : public TestTfliteParser { | class TestTfliteParserReverseSequence : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserReverseSequence() {} | |||||
| TestTfliteParserReverseSequence() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./reverse_sequence.tflite"); | meta_graph = LoadAndConvert("./reverse_sequence.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserRound : public TestTfliteParser { | class TestTfliteParserRound : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserRound() {} | |||||
| TestTfliteParserRound() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./round.tflite"); | meta_graph = LoadAndConvert("./round.tflite"); | ||||
| } | } | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserRsqrt : public TestTfliteParser { | class TestTfliteParserRsqrt : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserRsqrt() {} | |||||
| TestTfliteParserRsqrt() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSin : public TestTfliteParser { | class TestTfliteParserSin : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSin() {} | |||||
| TestTfliteParserSin() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSpaceToBatchND : public TestTfliteParser { | class TestTfliteParserSpaceToBatchND : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSpaceToBatchND() {} | |||||
| TestTfliteParserSpaceToBatchND() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./space_to_batch_nd.tflite"); | meta_graph = LoadAndConvert("./space_to_batch_nd.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSpaceToDepth : public TestTfliteParser { | class TestTfliteParserSpaceToDepth : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSpaceToDepth() {} | |||||
| TestTfliteParserSpaceToDepth() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./space_to_depth.tflite"); | meta_graph = LoadAndConvert("./space_to_depth.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSparseToDense : public TestTfliteParser { | class TestTfliteParserSparseToDense : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSparseToDense() {} | |||||
| TestTfliteParserSparseToDense() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./sparse_to_dense.tflite"); | meta_graph = LoadAndConvert("./sparse_to_dense.tflite"); | ||||
| } | } | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSplit : public TestTfliteParser { | class TestTfliteParserSplit : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSplit() {} | |||||
| TestTfliteParserSplit() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSplitV : public TestTfliteParser { | class TestTfliteParserSplitV : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSplitV() {} | |||||
| TestTfliteParserSplitV() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } | ||||
| }; | }; | ||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSqrt : public TestTfliteParser { | class TestTfliteParserSqrt : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSqrt() {} | |||||
| TestTfliteParserSqrt() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSquare : public TestTfliteParser { | class TestTfliteParserSquare : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSquare() {} | |||||
| TestTfliteParserSquare() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } | void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSquaredDifference : public TestTfliteParser { | class TestTfliteParserSquaredDifference : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSquaredDifference() {} | |||||
| TestTfliteParserSquaredDifference() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./squared_difference.tflite"); | meta_graph = LoadAndConvert("./squared_difference.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserStridedSlice : public TestTfliteParser { | class TestTfliteParserStridedSlice : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserStridedSlice() {} | |||||
| TestTfliteParserStridedSlice() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./strided_slice.tflite"); | meta_graph = LoadAndConvert("./strided_slice.tflite"); | ||||
| } | } | ||||
| @@ -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 <iostream> | |||||
| #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 | |||||
| @@ -20,7 +20,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserSum : public TestTfliteParser { | class TestTfliteParserSum : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserSum() {} | |||||
| TestTfliteParserSum() = default; | |||||
| void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } | void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } | ||||
| }; | }; | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserTile : public TestTfliteParser { | class TestTfliteParserTile : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserTile() {} | |||||
| TestTfliteParserTile() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./tile.tflite"); | meta_graph = LoadAndConvert("./tile.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserTopKV2 : public TestTfliteParser { | class TestTfliteParserTopKV2 : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserTopKV2() {} | |||||
| TestTfliteParserTopKV2() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./topk_v2.tflite"); | meta_graph = LoadAndConvert("./topk_v2.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserUnique : public TestTfliteParser { | class TestTfliteParserUnique : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserUnique() {} | |||||
| TestTfliteParserUnique() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./unique.tflite"); | meta_graph = LoadAndConvert("./unique.tflite"); | ||||
| } | } | ||||
| @@ -21,7 +21,7 @@ | |||||
| namespace mindspore { | namespace mindspore { | ||||
| class TestTfliteParserUnstack : public TestTfliteParser { | class TestTfliteParserUnstack : public TestTfliteParser { | ||||
| public: | public: | ||||
| TestTfliteParserUnstack() {} | |||||
| TestTfliteParserUnstack() = default; | |||||
| void SetUp() override { | void SetUp() override { | ||||
| meta_graph = LoadAndConvert("./unstack.tflite"); | meta_graph = LoadAndConvert("./unstack.tflite"); | ||||
| } | } | ||||
| @@ -14,9 +14,9 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "tools/converter/parser/tflite/tflite_abs_parser.h" | |||||
| #include <vector> | #include <vector> | ||||
| #include <memory> | #include <memory> | ||||
| #include "tools/converter/parser/tflite/tflite_abs_parser.h" | |||||
| namespace mindspore { | namespace mindspore { | ||||
| namespace lite { | namespace lite { | ||||
| @@ -24,9 +24,7 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfliteOp | |||||
| const std::vector<std::unique_ptr<tflite::TensorT>> &tfliteTensors, | 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::BufferT>> &tfliteModelBuffer, | ||||
| const std::vector<std::unique_ptr<tflite::OperatorCodeT>> &tfliteOpSet, | 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(DEBUG) << "parse TfliteAddParser"; | MS_LOG(DEBUG) << "parse TfliteAddParser"; | ||||
| std::unique_ptr<schema::AddT> attr(new schema::AddT()); | std::unique_ptr<schema::AddT> attr(new schema::AddT()); | ||||
| const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); | const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); | ||||
| @@ -34,14 +32,46 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfliteOp | |||||
| MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; | MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; | ||||
| return RET_NULL_PTR; | 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<tflite::TensorT *> 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<tflite::TensorT *> 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<tflite::TensorT *> 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) { | if (op != nullptr) { | ||||
| op->primitive = std::make_unique<schema::PrimitiveT>(); | op->primitive = std::make_unique<schema::PrimitiveT>(); | ||||
| op->primitive->value.type = schema::PrimitiveType_Add; | op->primitive->value.type = schema::PrimitiveType_Add; | ||||
| @@ -15,22 +15,22 @@ | |||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #include "tools/converter/parser/tflite/tflite_addn_parser.h" | |||||
| #include <vector> | #include <vector> | ||||
| #include <memory> | #include <memory> | ||||
| #include "tools/converter/parser/tflite/tflite_addn_parser.h" | |||||
| namespace mindspore { | namespace mindspore { | ||||
| namespace lite { | namespace lite { | ||||
| STATUS TfliteAddNParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite_op, | |||||
| const std::vector<std::unique_ptr<tflite::TensorT>> &tflite_tensors, | |||||
| const std::vector<std::unique_ptr<tflite::BufferT>> &tflite_model_buffer, | |||||
| const std::vector<std::unique_ptr<tflite::OperatorCodeT>> &tflite_opset, | |||||
| schema::CNodeT *op, | |||||
| TensorCache *tensor_cache, | |||||
| bool quantized_model) { | |||||
| STATUS TfliteAddNParser::Parse(const std::unique_ptr<tflite::OperatorT> &tfliteOp, | |||||
| 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) { | |||||
| MS_LOG(DEBUG) << "parse TfliteAddNParser"; | MS_LOG(DEBUG) << "parse TfliteAddNParser"; | ||||
| std::unique_ptr<schema::AddNT> attr(new schema::AddNT()); | std::unique_ptr<schema::AddNT> attr(new schema::AddNT()); | ||||
| attr->N = tflite_tensors.size() - 1; | |||||
| attr->N = tfliteTensors.size() - 1; | |||||
| if (op != nullptr) { | if (op != nullptr) { | ||||
| op->primitive = std::make_unique<schema::PrimitiveT>(); | op->primitive = std::make_unique<schema::PrimitiveT>(); | ||||
| op->primitive->value.type = schema::PrimitiveType_AddN; | op->primitive->value.type = schema::PrimitiveType_AddN; | ||||
| @@ -29,11 +29,25 @@ STATUS TfliteArgmaxParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit | |||||
| bool quantizedModel) { | bool quantizedModel) { | ||||
| MS_LOG(DEBUG) << "parse TfliteArgmaxParser"; | MS_LOG(DEBUG) << "parse TfliteArgmaxParser"; | ||||
| std::unique_ptr<schema::ArgMaxT> attr(new schema::ArgMaxT()); | std::unique_ptr<schema::ArgMaxT> attr(new schema::ArgMaxT()); | ||||
| // These are caffe attributes, set to default value. | |||||
| attr->axisType = 1; | |||||
| attr->outMaxValue = false; | attr->outMaxValue = false; | ||||
| attr->topK = 1; | attr->topK = 1; | ||||
| attr->keepDims = false; | 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<int32_t *>(static_cast<void *>(data_ptr))); | |||||
| if (op != nullptr) { | if (op != nullptr) { | ||||
| op->primitive = std::make_unique<schema::PrimitiveT>(); | op->primitive = std::make_unique<schema::PrimitiveT>(); | ||||