Browse Source

!4039 add ut for 21 tflite op parsers

Merge pull request !4039 from wangzhe/master
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
f9e8ec3fd7
50 changed files with 871 additions and 25 deletions
  1. +4
    -0
      mindspore/lite/test/CMakeLists.txt
  2. +3
    -0
      mindspore/lite/test/run_test.sh
  3. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite
  4. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite
  5. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cos.tflite
  6. +0
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite
  7. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite
  8. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite
  9. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_not.tflite
  10. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite
  11. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/maximum.tflite
  12. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite
  13. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite
  14. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite
  15. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_min.tflite
  16. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite
  17. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite
  18. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite
  19. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split.tflite
  20. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite
  21. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite
  22. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite
  23. BIN
      mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sum.tflite
  24. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc
  25. +45
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc
  26. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc
  27. +10
    -19
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc
  28. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc
  29. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc
  30. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc
  31. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc
  32. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc
  33. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc
  34. +43
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc
  35. +33
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc
  36. +35
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h
  37. +46
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc
  38. +46
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc
  39. +46
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc
  40. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc
  41. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc
  42. +46
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc
  43. +46
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc
  44. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc
  45. +34
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc
  46. +47
    -0
      mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc
  47. +4
    -3
      mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc
  48. +6
    -2
      mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc
  49. +2
    -0
      mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc
  50. +1
    -1
      mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc

+ 4
- 0
mindspore/lite/test/CMakeLists.txt View File

@@ -191,8 +191,12 @@ if (SUPPORT_GPU)
endif() endif()
### converter ### converter
if(BUILD_CONVERTER) if(BUILD_CONVERTER)
file(GLOB_RECURSE TEST_CASE_TFLITE_PARSERS_SRC
${TEST_DIR}/ut/tools/converter/parser/tflite/*.cc
)
set(TEST_LITE_SRC set(TEST_LITE_SRC
${TEST_LITE_SRC} ${TEST_LITE_SRC}
${TEST_CASE_TFLITE_PARSERS_SRC}
${TOP_DIR}/mindspore/core/utils/flags.cc ${TOP_DIR}/mindspore/core/utils/flags.cc
${LITE_DIR}/tools/converter/optimizer.cc ${LITE_DIR}/tools/converter/optimizer.cc
${LITE_DIR}/src/common/anf_importer/anf_importer.cc ${LITE_DIR}/src/common/anf_importer/anf_importer.cc


+ 3
- 0
mindspore/lite/test/run_test.sh View File

@@ -7,6 +7,7 @@ mkdir -pv ${CUR_DIR}/do_test
cd ${CUR_DIR}/do_test cd ${CUR_DIR}/do_test
cp ${BUILD_DIR}/test/lite-test ./ cp ${BUILD_DIR}/test/lite-test ./
cp -r ${CUR_DIR}/ut/src/runtime/kernel/arm/test_data/* ./ cp -r ${CUR_DIR}/ut/src/runtime/kernel/arm/test_data/* ./
cp -r ${CUR_DIR}/ut/tools/converter/parser/tflite/test_data/* ./
## prepare data for dataset ## prepare data for dataset
TEST_DATA_DIR=${CUR_DIR}/../../../tests/ut/data/dataset/ TEST_DATA_DIR=${CUR_DIR}/../../../tests/ut/data/dataset/
cp -fr $TEST_DATA_DIR/testPK ./data cp -fr $TEST_DATA_DIR/testPK ./data
@@ -14,6 +15,8 @@ cp -fr $TEST_DATA_DIR/testPK ./data
./lite-test --gtest_filter="*MindDataTestTensorDE*" ./lite-test --gtest_filter="*MindDataTestTensorDE*"
./lite-test --gtest_filter="*MindDataTestEager*" ./lite-test --gtest_filter="*MindDataTestEager*"


./lite-test --gtest_filter="TestTfliteParser*"

./lite-test --gtest_filter="*TestHebing*" ./lite-test --gtest_filter="*TestHebing*"


./lite-test --gtest_filter=TestFcFp32* ./lite-test --gtest_filter=TestFcFp32*


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/abs.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/batch_to_space_nd.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/cos.tflite View File


mindspore/lite/test/ut/tools/converter/parser/test_data/tflite_exp_model/Exp.tflite → mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/exp.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/log.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_and.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_not.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/logical_or.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/maximum.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/minimum.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/one_hot.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_max.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_min.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reduce_prod.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rsqrt.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sin.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/split_v.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sqrt.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/square.tflite View File


BIN
mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sum.tflite View File


+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserAbs : public TestTfliteParser {
public:
TestTfliteParserAbs() {}
void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); }
};

TEST_F(TestTfliteParserAbs, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Abs) << "wrong Op Type";
}

} // namespace mindspore

+ 45
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc View File

@@ -0,0 +1,45 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserBatchToSpaceNd : public TestTfliteParser {
public:
TestTfliteParserBatchToSpaceNd() {}
void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); }
};

TEST_F(TestTfliteParserBatchToSpaceNd, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_BatchToSpace) << "wrong Op Type";
}

TEST_F(TestTfliteParserBatchToSpaceNd, AttrValue) {
const std::vector<int> blockShape{2, 2};
const std::vector<int> crops{0, 0, 2, 0};
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsBatchToSpace(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsBatchToSpace()->blockShape, blockShape);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsBatchToSpace()->crops, crops);
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserCos : public TestTfliteParser {
public:
TestTfliteParserCos() {}
void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); }
};

TEST_F(TestTfliteParserCos, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Cos) << "wrong Op Type";
}

} // namespace mindspore

+ 10
- 19
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_exp_parser_test.cc View File

@@ -13,31 +13,22 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream> #include <iostream>
#include "mindspore/core/utils/log_adapter.h"
#include "common/common_test.h" #include "common/common_test.h"
#include "tools/converter/converter_flags.h"
#include "schema/inner/model_generated.h"
#include "tools/converter/parser/tflite/tflite_converter.h"
#include "tools/converter/parser/tflite/tflite_exp_parser.h"
#include "src/kernel_registry.h"
#include "src/lite_kernel.h"


namespace mindspore { namespace mindspore {

class TestTfliteExpParser : public mindspore::Common {
class TestTfliteParserExp : public TestTfliteParser {
public: public:
TestTfliteExpParser() {}
TestTfliteParserExp() {}
void SetUp() override { meta_graph = LoadAndConvert("./exp.tflite", ""); }
}; };


TEST_F(TestTfliteExpParser, ExpParser) {
lite::converter::Flags flags;
flags.modelFile = "./test_data/Exp.tflite";
flags.fmk = lite::converter::FmkType_TFLITE;
lite::TfliteConverter converter;
schema::MetaGraphT *fb_graph = nullptr;
fb_graph = converter.Convert(&flags);
const auto &nodes = fb_graph->nodes;
nodes.back();
TEST_F(TestTfliteParserExp, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Exp) << "wrong Op Type";
} }

} // namespace mindspore } // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserLog : public TestTfliteParser {
public:
TestTfliteParserLog() {}
void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); }
};

TEST_F(TestTfliteParserLog, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Log) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteLogicalParserAnd : public TestTfliteParser {
public:
TestTfliteLogicalParserAnd() {}
void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); }
};

TEST_F(TestTfliteLogicalParserAnd, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_LogicalAnd) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserLogicalNot : public TestTfliteParser {
public:
TestTfliteParserLogicalNot() {}
void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); }
};

TEST_F(TestTfliteParserLogicalNot, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_LogicalNot) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserLogicalOr : public TestTfliteParser {
public:
TestTfliteParserLogicalOr() {}
void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); }
};

TEST_F(TestTfliteParserLogicalOr, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_LogicalOr) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserMaximum : public TestTfliteParser {
public:
TestTfliteParserMaximum() {}
void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); }
};

TEST_F(TestTfliteParserMaximum, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Maximum) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserMinimum : public TestTfliteParser {
public:
TestTfliteParserMinimum() {}
void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); }
};

TEST_F(TestTfliteParserMinimum, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Minimum) << "wrong Op Type";
}

} // namespace mindspore

+ 43
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc View File

@@ -0,0 +1,43 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserOneHot : public TestTfliteParser {
public:
TestTfliteParserOneHot() {}
void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); }
};

TEST_F(TestTfliteParserOneHot, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_OneHot) << "wrong Op Type";
}

TEST_F(TestTfliteParserOneHot, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsOneHot(), nullptr);
// in OneHot parser axis = axis > 0 ? axis : axis + tensor_shape.size()
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsOneHot()->axis, 2);
}

} // namespace mindspore

+ 33
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc View File

@@ -0,0 +1,33 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <string>
#include "schema/inner/model_generated.h"
#include "tools/converter/parser/tflite/tflite_model_parser.h"

namespace mindspore {

schema::MetaGraphT *TestTfliteParser::LoadAndConvert(const string &model_path, const string &weight_path) {
schema::MetaGraphT *meta_graph = nullptr;
lite::TfliteModelParser parser;
meta_graph = parser.Parse(model_path, weight_path);
return meta_graph;
}

void TestTfliteParser::TearDown() { free(meta_graph); }

} // namespace mindspore

+ 35
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h View File

@@ -0,0 +1,35 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_
#define MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_

#include <string>
#include "common/common_test.h"
#include "schema/inner/model_generated.h"

namespace mindspore {
class TestTfliteParser : public Common {
public:
TestTfliteParser() {}
void TearDown() override;
schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = "");
schema::MetaGraphT *meta_graph;
};

} // namespace mindspore

#endif // MINDSPORE_LITE_TEST_UT_TOOLS_CONVERTER_PARSER_TFLITE_TFLITE_PARSERS_TEST_H_

+ 46
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserReduceMax : public TestTfliteParser {
public:
TestTfliteParserReduceMax() {}
void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); }
};

TEST_F(TestTfliteParserReduceMax, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reduce) << "wrong Op Type";
}

TEST_F(TestTfliteParserReduceMax, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceMax)
<< "wrong reduce mode";
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2);
}

} // namespace mindspore

+ 46
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserReduceMin : public TestTfliteParser {
public:
TestTfliteParserReduceMin() {}
void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); }
};

TEST_F(TestTfliteParserReduceMin, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reduce) << "wrong Op Type";
}

TEST_F(TestTfliteParserReduceMin, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceMin)
<< "wrong reduce mode";
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2);
}

} // namespace mindspore

+ 46
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserReduceProd : public TestTfliteParser {
public:
TestTfliteParserReduceProd() {}
void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); }
};

TEST_F(TestTfliteParserReduceProd, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reduce) << "wrong Op Type";
}

TEST_F(TestTfliteParserReduceProd, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceProd)
<< "wrong reduce mode";
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2);
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserRsqrt : public TestTfliteParser {
public:
TestTfliteParserRsqrt() {}
void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); }
};

TEST_F(TestTfliteParserRsqrt, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Rsqrt) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserSin : public TestTfliteParser {
public:
TestTfliteParserSin() {}
void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); }
};

TEST_F(TestTfliteParserSin, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sin) << "wrong Op Type";
}

} // namespace mindspore

+ 46
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserSplit : public TestTfliteParser {
public:
TestTfliteParserSplit() {}

void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); }
};

TEST_F(TestTfliteParserSplit, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Split) << "wrong Op Type";
}

TEST_F(TestTfliteParserSplit, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsSplit(), nullptr);
const std::vector<int> sizeSplits{2, 2};
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->splitDim, 2);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->numberSplit, 2);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->sizeSplits, sizeSplits);
}

} // namespace mindspore

+ 46
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc View File

@@ -0,0 +1,46 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserSplitV : public TestTfliteParser {
public:
TestTfliteParserSplitV() {}

void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); }
};

TEST_F(TestTfliteParserSplitV, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Split) << "wrong Op Type";
}

TEST_F(TestTfliteParserSplitV, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsSplit(), nullptr);
const std::vector<int> sizeSplits{1, 3};
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->splitDim, 0);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->numberSplit, 2);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsSplit()->sizeSplits, sizeSplits);
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserSqrt : public TestTfliteParser {
public:
TestTfliteParserSqrt() {}
void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); }
};

TEST_F(TestTfliteParserSqrt, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sqrt) << "wrong Op Type";
}

} // namespace mindspore

+ 34
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc View File

@@ -0,0 +1,34 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserSquare : public TestTfliteParser {
public:
TestTfliteParserSquare() {}
void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); }
};

TEST_F(TestTfliteParserSquare, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Square) << "wrong Op Type";
}

} // namespace mindspore

+ 47
- 0
mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc View File

@@ -0,0 +1,47 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h"
#include <iostream>
#include "common/common_test.h"

namespace mindspore {
class TestTfliteParserSum : public TestTfliteParser {
public:
TestTfliteParserSum() {}

void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); }
};

TEST_F(TestTfliteParserSum, OpType) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reduce) << "wrong Op Type";
}

TEST_F(TestTfliteParserSum, AttrValue) {
ASSERT_NE(meta_graph, nullptr);
ASSERT_GT(meta_graph->nodes.size(), 0);
ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr);
ASSERT_NE(meta_graph->nodes.front()->primitive->value.AsReduce(), nullptr);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->mode, schema::ReduceMode_ReduceSum)
<< "wrong reduce mode";
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->keepDims, false);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes.size(), 1);
ASSERT_EQ(meta_graph->nodes.front()->primitive->value.AsReduce()->axes[0], 2);
}

} // namespace mindspore

+ 4
- 3
mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc View File

@@ -24,12 +24,13 @@ STATUS TfliteBatchToSpaceNDParser::Parse(const std::unique_ptr<tflite::OperatorT
const std::vector<std::unique_ptr<tflite::TensorT>> &tfliteTensors, const std::vector<std::unique_ptr<tflite::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(INFO) << "parse TfliteBatchToSpaceNDParser"; MS_LOG(INFO) << "parse TfliteBatchToSpaceNDParser";
std::unique_ptr<schema::BatchToSpaceT> attr(new schema::BatchToSpaceT()); std::unique_ptr<schema::BatchToSpaceT> attr(new schema::BatchToSpaceT());


// in tflite
// blockShape should be a 1D tensor with dimension [spatial_dims_num]
// crops should be a 2D tensor with dimension [spatial_dims_num, 2]
if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) {
MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed"; MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed";
return RET_ERROR; return RET_ERROR;


+ 6
- 2
mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc View File

@@ -32,8 +32,12 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflit
MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; MS_LOG(ERROR) << "get op: " << op->name << " attr failed";
return RET_NULL_PTR; return RET_NULL_PTR;
} }

attr->axis = tflite_attr->axis;
auto axis = tflite_attr->axis;
const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape;
if (axis < 0) {
axis += tensor_shape.size();
}
attr->axis = axis;


if (op != nullptr) { if (op != nullptr) {
op->primitive = std::make_unique<schema::PrimitiveT>(); op->primitive = std::make_unique<schema::PrimitiveT>();


+ 2
- 0
mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc View File

@@ -39,6 +39,8 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr<tflite::OperatorT> &tf
MS_LOG(DEBUG) << i; MS_LOG(DEBUG) << i;
} }
*/ */
// in tflite, kIndices = 0, kUpdates = 1, kShape = 2
// in mslite, kScatterShapeIndex = 0, kScatterIndicesIndex = 1, kScatterUpdateIndex = 2;
std::swap(op->inputIndex[0], op->inputIndex[2]); std::swap(op->inputIndex[0], op->inputIndex[2]);
std::swap(op->inputIndex[1], op->inputIndex[2]); std::swap(op->inputIndex[1], op->inputIndex[2]);
/* /*


+ 1
- 1
mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc View File

@@ -54,7 +54,7 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr<tflite::OperatorT> &tflite
} }
attr->numberSplit = num_splits; attr->numberSplit = num_splits;


for (int i = 0; i <= num_splits; i++) {
for (int i = 0; i < num_splits; i++) {
attr->sizeSplits.push_back(tensor_shape[axis] / num_splits); attr->sizeSplits.push_back(tensor_shape[axis] / num_splits);
} }




Loading…
Cancel
Save