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_caffe_parser.cc 3.2 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Copyright 2021 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 "graph/operator_reg.h"
  19. #include "register/op_registry.h"
  20. #include "parser/common/register_tbe.h"
  21. #include "framework/omg/parser/model_parser.h"
  22. #include "framework/omg/parser/parser_factory.h"
  23. #include "external/parser/caffe_parser.h"
  24. #include "st/parser_st_utils.h"
  25. #include "external/ge/ge_api_types.h"
  26. #include "tests/depends/ops_stub/ops_stub.h"
  27. namespace ge {
  28. class STestCaffeParser : public testing::Test {
  29. protected:
  30. void SetUp() {
  31. ParerSTestsUtils::ClearParserInnerCtx();
  32. RegisterCustomOp();
  33. }
  34. void TearDown() {}
  35. public:
  36. void RegisterCustomOp();
  37. };
  38. static Status ParseParams(const google::protobuf::Message* op_src, ge::Operator& op_dest) {
  39. return SUCCESS;
  40. }
  41. void STestCaffeParser::RegisterCustomOp() {
  42. REGISTER_CUSTOM_OP("Data")
  43. .FrameworkType(domi::CAFFE)
  44. .OriginOpType("Input")
  45. .ParseParamsFn(ParseParams);
  46. REGISTER_CUSTOM_OP("Abs")
  47. .FrameworkType(domi::CAFFE)
  48. .OriginOpType("AbsVal")
  49. .ParseParamsFn(ParseParams);
  50. std::vector<OpRegistrationData> reg_datas = domi::OpRegistry::Instance()->registrationDatas;
  51. for (auto reg_data : reg_datas) {
  52. OpRegistrationTbe::Instance()->Finalize(reg_data);
  53. domi::OpRegistry::Instance()->Register(reg_data);
  54. }
  55. domi::OpRegistry::Instance()->registrationDatas.clear();
  56. }
  57. TEST_F(STestCaffeParser, caffe_parser_user_output_with_default) {
  58. std::string case_dir = __FILE__;
  59. case_dir = case_dir.substr(0, case_dir.find_last_of("/"));
  60. std::string model_file = case_dir + "/origin_models/caffe_abs.pbtxt";
  61. auto model_parser = domi::ModelParserFactory::Instance()->CreateModelParser(domi::CAFFE);
  62. ASSERT_NE(model_parser, nullptr);
  63. ge::ComputeGraphPtr compute_graph = ge::parser::MakeShared<ge::ComputeGraph>("tmp_graph");
  64. ASSERT_NE(compute_graph, nullptr);
  65. ge::Graph graph = ge::GraphUtils::CreateGraphFromComputeGraph(compute_graph);
  66. auto ret = model_parser->Parse(model_file.c_str(), graph);
  67. ASSERT_EQ(ret, GRAPH_SUCCESS);
  68. AclGrphParseUtil acl_graph_parse_util;
  69. std::map<AscendString, AscendString> parser_params;
  70. auto status = acl_graph_parse_util.SetOutputNodeInfo(graph, parser_params);
  71. ASSERT_EQ(status, SUCCESS);
  72. auto output_nodes_info = compute_graph->GetGraphOutNodesInfo();
  73. ASSERT_EQ(output_nodes_info.size(), 1);
  74. EXPECT_EQ((output_nodes_info.at(0).first->GetName()), "abs");
  75. EXPECT_EQ((output_nodes_info.at(0).second), 0);
  76. auto &net_out_name = ge::GetParserContext().net_out_nodes;
  77. ASSERT_EQ(net_out_name.size(), 1);
  78. EXPECT_EQ(net_out_name.at(0), "abs:0:abs_out");
  79. }
  80. } // namespace ge