diff --git a/mindspore/lite/schema/ops.fbs b/mindspore/lite/schema/ops.fbs index 78278b0c3a3d6d6c50e928d385bfc88e3a727adb..a870a6bb01af39df83e71e95e76ac50a120956bd 100644 --- a/mindspore/lite/schema/ops.fbs +++ b/mindspore/lite/schema/ops.fbs @@ -384,15 +384,19 @@ table Eltwise { } table Add { + activationType : ActivationType; } table Sub { + activationType : ActivationType; } table Mul { + activationType : ActivationType; } table Div { + activationType : ActivationType; } table AddGrad { diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/addn.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/addn.tflite new file mode 100644 index 0000000000000000000000000000000000000000..d704d5d80d1954224243a29f080503269d9fe77c Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/addn.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cast.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cast.tflite new file mode 100644 index 0000000000000000000000000000000000000000..0369c361119fd8cf6c7ba070316d5a28401f6c32 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cast.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/depth_to_space.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/depth_to_space.tflite new file mode 100644 index 0000000000000000000000000000000000000000..2f9dbe01c42e40c4b52f33697b657b08f33d4093 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/depth_to_space.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/equal.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/equal.tflite new file mode 100644 index 0000000000000000000000000000000000000000..b0325f43ecf7162377d0cf83d45a132e7fa5d02b Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/equal.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite deleted file mode 100644 index 34555df3d23d4f397d4506593773f0799dff194f..0000000000000000000000000000000000000000 Binary files a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite and /dev/null differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/greater.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/greater.tflite new file mode 100644 index 0000000000000000000000000000000000000000..6bf638e1576ad1aa69c8f67e15303aeff54ad24e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/greater.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/greater_equal.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/greater_equal.tflite new file mode 100644 index 0000000000000000000000000000000000000000..eabe74532540745c27f7a002b72c26522bbd30f6 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/greater_equal.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/less.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/less.tflite new file mode 100644 index 0000000000000000000000000000000000000000..9d76ebcefd948d85471f831b2759eb6852eade63 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/less.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/less_equal.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/less_equal.tflite new file mode 100644 index 0000000000000000000000000000000000000000..7d9898d6271c3af94dce5463635d24e80466ec28 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/less_equal.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/not_equal.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/not_equal.tflite new file mode 100644 index 0000000000000000000000000000000000000000..580f650e2360fee443303c2a23063b44531a6936 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/not_equal.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/prelu.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/prelu.tflite new file mode 100644 index 0000000000000000000000000000000000000000..dd432b62acef9b8d857c7838a5661987fbefe484 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/prelu.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse_sequence.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse_sequence.tflite new file mode 100644 index 0000000000000000000000000000000000000000..171aaa8caefa864f5dc5661db64b0918a4c5163e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse_sequence.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/round.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/round.tflite new file mode 100644 index 0000000000000000000000000000000000000000..1c777757379048dde407d7954dc0b83820842575 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/round.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/space_to_batch_nd.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/space_to_batch_nd.tflite new file mode 100644 index 0000000000000000000000000000000000000000..f05f6fef85a9b60295335a3819d11eaa7865d049 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/space_to_batch_nd.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/space_to_depth.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/space_to_depth.tflite new file mode 100644 index 0000000000000000000000000000000000000000..3ed48958f084a95fbab84185588ba5f19858ddf4 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/space_to_depth.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sparse_to_dense.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sparse_to_dense.tflite new file mode 100644 index 0000000000000000000000000000000000000000..b3ef9112d30b062fdd7ee0c890daafa60838511f Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sparse_to_dense.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 index 8bd23c38c7eda6abecf226bb9a8bbacdd9616d85..4c907b4a1f4b1a8d84ee5a2cb9614dddb0ff068d 100644 Binary files a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite 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/squared_difference.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squared_difference.tflite new file mode 100644 index 0000000000000000000000000000000000000000..e0f454a5e62868985c7f079e3151d4d18e79530e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squared_difference.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/strided_slice.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/strided_slice.tflite new file mode 100644 index 0000000000000000000000000000000000000000..d586c1faabbf3390072de9777fb5620d4084d164 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/strided_slice.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/tile.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/tile.tflite new file mode 100644 index 0000000000000000000000000000000000000000..b959b4bfdc0756dd6e08eab0f8ba710f4258ef35 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/tile.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/topk_v2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/topk_v2.tflite new file mode 100644 index 0000000000000000000000000000000000000000..4f8e658707d01e2a32b4ede2d02a5ff2081d8f98 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/topk_v2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/unique.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/unique.tflite new file mode 100644 index 0000000000000000000000000000000000000000..9bd16c5ddf3e0e7b6b6dc08d1075f4b3ba412cb2 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/unique.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/unstack.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/unstack.tflite new file mode 100644 index 0000000000000000000000000000000000000000..93703929f91f391cf7df50ef192bb111de3ed98d Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/unstack.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..89519cea108ceb2130a449d0c6dcf970dfc12ed6 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserAddN : public TestTfliteParser { + public: + TestTfliteParserAddN() {} + void SetUp() override { + meta_graph = LoadAndConvert("./addn.tflite"); + } +}; + +TEST_F(TestTfliteParserAddN, 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_AddN) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAddN, 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.AsAddN(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsAddN()->N, 4); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..c986d595d7dcc4193fceb9fbed6784013575d54d --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_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 +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserCast : public TestTfliteParser { + public: + TestTfliteParserCast() {} + void SetUp() override { + meta_graph = LoadAndConvert("./cast.tflite"); + } +}; + +TEST_F(TestTfliteParserCast, 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_Cast) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserCast, AttrValue) { + // float32 --> int32 + 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.AsCast(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsCast()->srcT, 43); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsCast()->dstT, 34); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..d1983e0b848a50d8ac803e9cc78faab8066fe397 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserDepthToSpace : public TestTfliteParser { + public: + TestTfliteParserDepthToSpace() {} + void SetUp() override { + meta_graph = LoadAndConvert("./depth_to_space.tflite"); + } +}; + +TEST_F(TestTfliteParserDepthToSpace, 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_DepthToSpace) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDepthToSpace, 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.AsDepthToSpace(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsDepthToSpace()->blockSize, 4); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsDepthToSpace()->format, schema::Format_NHWC); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..7e816a9d39b616cbc02b6116fa40721864a4bf5b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserEqual : public TestTfliteParser { + public: + TestTfliteParserEqual() {} + void SetUp() override { + meta_graph = LoadAndConvert("./equal.tflite"); + } +}; + +TEST_F(TestTfliteParserEqual, 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_Equal) << "wrong Op Type"; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..3b5dba47c208d3c714da06f74933062db92b4112 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGreaterEqual : public TestTfliteParser { + public: + TestTfliteParserGreaterEqual() {} + void SetUp() override { + meta_graph = LoadAndConvert("./greater_equal.tflite"); + } +}; + +TEST_F(TestTfliteParserGreaterEqual, 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_GreaterEqual) << "wrong Op Type"; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..055dbab7dac4cdad4974ae0608c85aca0151656d --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGreater : public TestTfliteParser { + public: + TestTfliteParserGreater() {} + void SetUp() override { + meta_graph = LoadAndConvert("./greater.tflite"); + } +}; + +TEST_F(TestTfliteParserGreater, 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_Greater) << "wrong Op Type"; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..6c1d29877fc4796bb4497470adb2d8e00b22794a --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLessEqual : public TestTfliteParser { + public: + TestTfliteParserLessEqual() {} + void SetUp() override { + meta_graph = LoadAndConvert("./less_equal.tflite"); + } +}; + +TEST_F(TestTfliteParserLessEqual, 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_LessEqual) << "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_less_parser_test.cc similarity index 80% rename from mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc rename to mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc index 5a09b9e42809b3606b3ff9ae7f2951940447de29..795acfce7df2dbedc8fe1c4e970dafd728854d74 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_less_parser_test.cc @@ -13,22 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" #include #include "common/common_test.h" namespace mindspore { -class TestTfliteParserExp : public TestTfliteParser { +class TestTfliteParserLess : public TestTfliteParser { public: - TestTfliteParserExp() {} - void SetUp() override { meta_graph = LoadAndConvert("./exp.tflite", ""); } + TestTfliteParserLess() {} + void SetUp() override { + meta_graph = LoadAndConvert("./less.tflite"); + } }; -TEST_F(TestTfliteParserExp, OpType) { +TEST_F(TestTfliteParserLess, 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"; + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Less) << "wrong Op Type"; } - } // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..e7260a1262e232d091c37be7948195ce04cd24b3 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserNotEqual : public TestTfliteParser { + public: + TestTfliteParserNotEqual() {} + void SetUp() override { + meta_graph = LoadAndConvert("./not_equal.tflite"); + } +}; + +TEST_F(TestTfliteParserNotEqual, 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_NotEqual) << "wrong Op Type"; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..11e5fe7c148dcf518087e0f0ea777fbdc426422c --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPrelu : public TestTfliteParser { + public: + TestTfliteParserPrelu() {} + void SetUp() override { + meta_graph = LoadAndConvert("./prelu.tflite"); + } +}; + +TEST_F(TestTfliteParserPrelu, 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_Prelu) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPrelu, AttrValue) { + std::vector slope(20, 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.AsPrelu(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsPrelu()->slope, slope); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..f1a972f6e46c57be215d9163160d8c5ec5467c37 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_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 +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReverseSequence : public TestTfliteParser { + public: + TestTfliteParserReverseSequence() {} + void SetUp() override { + meta_graph = LoadAndConvert("./reverse_sequence.tflite"); + } +}; + +TEST_F(TestTfliteParserReverseSequence, 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_ReverseSequence) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReverseSequence, AttrValue) { + std::vector seq_length{7, 2, 3, 5}; + 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.AsReverseSequence(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReverseSequence()->seqAxis, 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReverseSequence()->seqAxis, 1); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReverseSequence()->seqLengths, seq_length); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..ffb6a26ffe2027395366f31b24ce342755fd02ba --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserRound : public TestTfliteParser { + public: + TestTfliteParserRound() {} + void SetUp() override { + meta_graph = LoadAndConvert("./round.tflite"); + } +}; + +TEST_F(TestTfliteParserRound, 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_Round) << "wrong Op Type"; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..a9d66ceaf4fa1a17901c4af371f42a4288798607 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_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 +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSpaceToBatchND : public TestTfliteParser { + public: + TestTfliteParserSpaceToBatchND() {} + void SetUp() override { + meta_graph = LoadAndConvert("./space_to_batch_nd.tflite"); + } +}; + +TEST_F(TestTfliteParserSpaceToBatchND, 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_SpaceToBatchND) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSpaceToBatchND, AttrValue) { + std::vector blockshape{2, 2}; + std::vector padding{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.AsSpaceToBatchND(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSpaceToBatchND()->blockShape, blockshape); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSpaceToBatchND()->paddings, padding); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..76245204a771d3e913c847e575e28a0d8a0f5679 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSpaceToDepth : public TestTfliteParser { + public: + TestTfliteParserSpaceToDepth() {} + void SetUp() override { + meta_graph = LoadAndConvert("./space_to_depth.tflite"); + } +}; + +TEST_F(TestTfliteParserSpaceToDepth, 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_SpaceToDepth) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSpaceToDepth, 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.AsSpaceToDepth(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSpaceToDepth()->blockSize, 2); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSpaceToDepth()->format, schema::Format_NHWC); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..043fdbfe63406caf848e84e2361724602da84899 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc @@ -0,0 +1,50 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSparseToDense : public TestTfliteParser { + public: + TestTfliteParserSparseToDense() {} + void SetUp() override { + meta_graph = LoadAndConvert("./sparse_to_dense.tflite"); + } +}; + +TEST_F(TestTfliteParserSparseToDense, 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_SparseToDense) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSparseToDense, AttrValue) { + std::vector outputShape{5, 5}; + std::vector sparseValue{1}; + std::vector defaultValue{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.AsSparseToDense(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSparseToDense()->outputShape, outputShape); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSparseToDense()->sparseValue, sparseValue); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSparseToDense()->defaultValue, defaultValue); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSparseToDense()->validateIndices, false); +} +} // 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 index 5301c2302ae8e96ac4cfc77549811a19cf400178..96e0e71f0c85790b80ce013129cffec6b9452661 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" #include #include "common/common_test.h" @@ -30,5 +31,4 @@ TEST_F(TestTfliteParserSquare, OpType) { 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_squared_difference_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..f6be7a992dc730d6ef3e67159163a38d479cac23 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc @@ -0,0 +1,37 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSquaredDifference : public TestTfliteParser { + public: + TestTfliteParserSquaredDifference() {} + void SetUp() override { + meta_graph = LoadAndConvert("./squared_difference.tflite"); + } +}; + +TEST_F(TestTfliteParserSquaredDifference, 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_SquaredDifference) + << "wrong Op Type"; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..bbb327b99865eb79b2f21a912e4b276aad22a462 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc @@ -0,0 +1,55 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserStridedSlice : public TestTfliteParser { + public: + TestTfliteParserStridedSlice() {} + void SetUp() override { + meta_graph = LoadAndConvert("./strided_slice.tflite"); + } +}; + +TEST_F(TestTfliteParserStridedSlice, 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_StridedSlice) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserStridedSlice, AttrValue) { + std::vector begin{1, -1, 0}; + std::vector end{2, -3, 3}; + std::vector stride{1, -1, 1}; + std::vector isscale{3, 2, 3}; + 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.AsStridedSlice(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->beginMask, 0); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->endMask, 0); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->beginMask, 0); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->beginMask, 0); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->begin, begin); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->end, end); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->stride, stride); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsStridedSlice()->isScale, isscale); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..19401218f7c8b593c320085ed22e6df01fe506dc --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserTile : public TestTfliteParser { + public: + TestTfliteParserTile() {} + void SetUp() override { + meta_graph = LoadAndConvert("./tile.tflite"); + } +}; + +TEST_F(TestTfliteParserTile, 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_Tile) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserTile, AttrValue) { + std::vector multiply{2, 3, 4}; + 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.AsTile(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsTile()->multiples, multiply); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..d358fdb2d5c96036bf425ab964f25384c9e23139 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_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 +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserTopKV2 : public TestTfliteParser { + public: + TestTfliteParserTopKV2() {} + void SetUp() override { + meta_graph = LoadAndConvert("./topk_v2.tflite"); + } +}; + +TEST_F(TestTfliteParserTopKV2, 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_TopKV2) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserTopKV2, AttrValue) { + // attr->sorted default is true + std::vector k{3}; + 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.AsTopKV2(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsTopKV2()->k, k); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsTopKV2()->sorted, true); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..244abf8ee24cbd638dec3532651ce388b01b2310 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserUnique : public TestTfliteParser { + public: + TestTfliteParserUnique() {} + void SetUp() override { + meta_graph = LoadAndConvert("./unique.tflite"); + } +}; + +TEST_F(TestTfliteParserUnique, 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_Unique) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserUnique, 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.AsUnique(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsUnique()->outType, 34); // int32 +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc new file mode 100644 index 0000000000000000000000000000000000000000..e2c03a5bec11356846a600721c465721e40b7fee --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserUnstack : public TestTfliteParser { + public: + TestTfliteParserUnstack() {} + void SetUp() override { + meta_graph = LoadAndConvert("./unstack.tflite"); + } +}; + +TEST_F(TestTfliteParserUnstack, 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_Unstack) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserUnstack, 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.AsUnstack(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsUnstack()->num, 5); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsUnstack()->axis, 1); +} +} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc index a1c981ca61a96dfa5325e9615541225460e9d871..3981b4b6aebd0030104cae45a108b7fcfbb60441 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc @@ -29,6 +29,11 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp bool quantizedModel) { MS_LOG(DEBUG) << "parse TfliteAddParser"; std::unique_ptr attr(new schema::AddT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); + if (nullptr == tfliteAttr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; @@ -36,7 +41,7 @@ STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { return RET_ERROR; } - + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Add; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc index 70905aaebc9da6841b962a81986c64e5b711a1d1..5dc9ee5bfd82842a8c9833ab1c640e4a21510d85 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc @@ -30,7 +30,7 @@ STATUS TfliteAddNParser::Parse(const std::unique_ptr &tflite_ bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteAddNParser"; std::unique_ptr attr(new schema::AddNT()); - attr->N = tflite_tensors.size(); + attr->N = tflite_tensors.size() - 1; if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_AddN; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc index d81fb870755e9db7d5890032b3433a30bc6e1b10..a7cce134a6ee33adf1e08908ac8c2e92b9a811dc 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc @@ -29,14 +29,9 @@ STATUS TfliteCastParser::Parse(const std::unique_ptr &tflite_ TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteCastParser"; std::unique_ptr attr(new schema::CastT()); - const auto &tflite_attr = tflite_op->builtin_options.AsCastOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op:" << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - attr->srcT = tflite_attr->in_data_type; - attr->dstT = tflite_attr->out_data_type; + attr->srcT = dtype_map[tflite_tensors[tflite_op->inputs[0]]->type]; + attr->dstT = dtype_map[tflite_tensors[tflite_op->outputs[0]]->type]; if (op != nullptr) { op->primitive = std::make_unique(); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.h index 935389d5baeb063f07d8e55962fed063a8b614d7..843a1449299914e761a87216003f74cd860e863f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.h @@ -19,6 +19,7 @@ #include #include +#include #include "tools/converter/parser/tflite/tflite_node_parser.h" #include "tools/converter/parser/tflite/tflite_node_parser_registry.h" @@ -34,6 +35,19 @@ class TfliteCastParser : public TfliteNodeParser { const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) override; + + private: + std::map dtype_map = { + {tflite::TensorType_FLOAT64, TypeId::kNumberTypeFloat64}, + {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, + {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, + {tflite::TensorType_INT64, TypeId::kNumberTypeInt64}, + {tflite::TensorType_INT32, TypeId::kNumberTypeInt32}, + {tflite::TensorType_INT16, TypeId::kNumberTypeInt16}, + {tflite::TensorType_INT8, TypeId::kNumberTypeInt8}, + {tflite::TensorType_UINT8, TypeId::kNumberTypeUInt8}, + {tflite::TensorType_BOOL, TypeId::kNumberTypeBool}, + }; }; } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc index c9d52f6cab3637c974960f9cf2dc2352d2a7527c..b7b6efe123ea8fb5c4e42dcdb91349dadfcb87db 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc @@ -42,7 +42,7 @@ STATUS TfliteDivParser::Parse(const std::unique_ptr &tfliteOp MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } - + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Div; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc index 7d6647171e82ed8fb35810d87caebaa394add379..efdefbc743c01a255b3f694b949e3ef92822e8d7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc @@ -43,7 +43,7 @@ STATUS TfliteMulParser::Parse(const std::unique_ptr &tfliteOp MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } - + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Mul; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc index 8e805acd979a8d72f78a88224566db124050b835..86ed3d0a2a7636b0fb2a1df48d17fb82c10944b3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc @@ -29,11 +29,6 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr TensorCache *tensor_cache, bool quantized_model) { MS_LOG(DEBUG) << "parse TfliteSparseToDenseParser"; std::unique_ptr attr(new schema::SparseToDenseT()); - const auto &tflite_attr = tflite_op->builtin_options.AsSparseToDenseOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op:" << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->outputShape)) { MS_LOG(ERROR) << "sparseToDense -> outputShape get failed"; @@ -47,7 +42,7 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr MS_LOG(ERROR) << "sparseToDense -> defaultValue get failed"; return RET_ERROR; } - attr->validateIndices = tflite_attr->validate_indices; + attr->validateIndices = false; if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_SparseToDense; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc index 0590734bf0c6c5819d79cd1fec39c0b9652b3d04..1a517f149036cd46aab45ca76967d478ecd6617c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc @@ -40,7 +40,7 @@ STATUS TfliteSubParser::Parse(const std::unique_ptr &tfliteOp if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { MS_LOG(ERROR) << "parse weight failed"; } - + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Sub; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc index fe386d5736a44ac4a1cd096ee8011bb375274c16..12131d606f2d8c327e939cad75dd76bdccff4d49 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc @@ -35,7 +35,7 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit return RET_NULL_PTR; } - attr->outType = GetTfliteDataType(tflite_attr->idx_out_type); + attr->outType = dtype_map[tflite_attr->idx_out_type]; if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_Unique; diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.h index f0e3b30c450a7d5f241110bc619a9a1ea7d95412..331aa5e48f80106cf40bb010a13dd9b8115aff72 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.h @@ -19,6 +19,7 @@ #include #include +#include #include "tools/converter/parser/tflite/tflite_node_parser.h" #include "tools/converter/parser/tflite/tflite_node_parser_registry.h" @@ -34,6 +35,19 @@ class TfliteUniqueParser : public TfliteNodeParser { const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) override; + + private: + std::map dtype_map = { + {tflite::TensorType_FLOAT64, TypeId::kNumberTypeFloat64}, + {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, + {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, + {tflite::TensorType_INT64, TypeId::kNumberTypeInt64}, + {tflite::TensorType_INT32, TypeId::kNumberTypeInt32}, + {tflite::TensorType_INT16, TypeId::kNumberTypeInt16}, + {tflite::TensorType_INT8, TypeId::kNumberTypeInt8}, + {tflite::TensorType_UINT8, TypeId::kNumberTypeUInt8}, + {tflite::TensorType_BOOL, TypeId::kNumberTypeBool}, + }; }; } // namespace lite } // namespace mindspore