You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_tensorflow_parser.cc 2.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * Copyright 2019-2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <gtest/gtest.h>
  17. #include "parser/common/op_parser_factory.h"
  18. #include "parser/tensorflow/tensorflow_parser.h"
  19. #include "graph/operator_reg.h"
  20. #include "register/op_registry.h"
  21. #include "parser/common/register_tbe.h"
  22. #include "external/parser/tensorflow_parser.h"
  23. #include "st/parser_st_utils.h"
  24. #include "tests/depends/ops_stub/ops_stub.h"
  25. namespace ge {
  26. class STestTensorflowParser : public testing::Test {
  27. protected:
  28. void SetUp() {
  29. ParerSTestsUtils::ClearParserInnerCtx();
  30. }
  31. void TearDown() {}
  32. public:
  33. void RegisterCustomOp();
  34. };
  35. static Status ParseParams(const google::protobuf::Message* op_src, ge::Operator& op_dest) {
  36. return SUCCESS;
  37. }
  38. void STestTensorflowParser::RegisterCustomOp() {
  39. REGISTER_CUSTOM_OP("Add")
  40. .FrameworkType(domi::TENSORFLOW)
  41. .OriginOpType("Add")
  42. .ParseParamsFn(ParseParams);
  43. std::vector<OpRegistrationData> reg_datas = domi::OpRegistry::Instance()->registrationDatas;
  44. for (auto reg_data : reg_datas) {
  45. OpRegistrationTbe::Instance()->Finalize(reg_data);
  46. domi::OpRegistry::Instance()->Register(reg_data);
  47. }
  48. domi::OpRegistry::Instance()->registrationDatas.clear();
  49. }
  50. TEST_F(STestTensorflowParser, tensorflow_parser_success) {
  51. RegisterCustomOp();
  52. std::string case_dir = __FILE__;
  53. ParserOperator unused("Add");
  54. case_dir = case_dir.substr(0, case_dir.find_last_of("/"));
  55. std::string model_file = case_dir + "/origin_models/tf_add.pb";
  56. std::map<ge::AscendString, ge::AscendString> parser_params;
  57. ge::Graph graph;
  58. auto ret = ge::aclgrphParseTensorFlow(model_file.c_str(), parser_params, graph);
  59. ASSERT_EQ(ret, SUCCESS);
  60. ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph);
  61. auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
  62. ASSERT_EQ(output_nodes_info.size(), 1);
  63. EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "add_test_1");
  64. EXPECT_EQ((output_nodes_info.at(0).second), 0);
  65. auto &net_out_name = ge::GetParserContext().net_out_nodes;
  66. ASSERT_EQ(net_out_name.size(), 1);
  67. EXPECT_EQ(net_out_name.at(0), "add_test_1:0");
  68. }
  69. } // namespace ge