| @@ -1435,6 +1435,18 @@ Status CaffeModelParser::SaveDataLayerTops(const domi::caffe::LayerParameter &la | |||||
| return SUCCESS; | return SUCCESS; | ||||
| } | } | ||||
| Status CaffeModelParser::ReportLayerInvalid(const domi::caffe::NetParameter &proto, const std::string &path) const { | |||||
| if (proto.layers_size() > 0) { | |||||
| ErrorManager::GetInstance().ATCReportErrMessage("E11021", {"realpath"}, {path}); | |||||
| GELOGE(FAILED, "[Check][Size]The model file[%s] is consisted of layers-structure which is deprecated in Caffe " | |||||
| "and unsupported in ATC. The \"layers\" should be changed to \"layer\".", path.c_str()); | |||||
| } else { | |||||
| ErrorManager::GetInstance().ATCReportErrMessage("E11022"); | |||||
| GELOGE(FAILED, "[Check][Size]net layer num is zero, prototxt file may be invalid."); | |||||
| } | |||||
| return FAILED; | |||||
| } | |||||
| Status CaffeModelParser::Parse(const char *model_path, ge::ComputeGraphPtr &graph) { | Status CaffeModelParser::Parse(const char *model_path, ge::ComputeGraphPtr &graph) { | ||||
| bool has_error = false; | bool has_error = false; | ||||
| GE_CHECK_NOTNULL(model_path); | GE_CHECK_NOTNULL(model_path); | ||||
| @@ -1458,10 +1470,7 @@ Status CaffeModelParser::Parse(const char *model_path, ge::ComputeGraphPtr &grap | |||||
| "[Parse][Model] by custom proto failed, model path: %s.", model_path); | "[Parse][Model] by custom proto failed, model path: %s.", model_path); | ||||
| if (proto_message.layer_size() == 0) { | if (proto_message.layer_size() == 0) { | ||||
| ErrorManager::GetInstance().ATCReportErrMessage("E11021", {"realpath"}, {model_path}); | |||||
| GELOGE(FAILED, "[Check][Size]The model file[%s] is consisted of layers-structure which is deprecated in Caffe " | |||||
| "and unsupported in ATC. The \"layers\" should be changed to \"layer\".", model_path); | |||||
| return FAILED; | |||||
| return ReportLayerInvalid(proto_message, model_path); | |||||
| } | } | ||||
| GE_RETURN_WITH_LOG_IF_ERROR(ProtoTypePassManager::Instance().Run(&proto_message, domi::CAFFE), | GE_RETURN_WITH_LOG_IF_ERROR(ProtoTypePassManager::Instance().Run(&proto_message, domi::CAFFE), | ||||
| @@ -313,6 +313,8 @@ class PARSER_FUNC_VISIBILITY CaffeModelParser : public domi::ModelParser { | |||||
| Status SaveDataLayerTops(const domi::caffe::LayerParameter &layer); | Status SaveDataLayerTops(const domi::caffe::LayerParameter &layer); | ||||
| Status ReportLayerInvalid(const domi::caffe::NetParameter &proto, const std::string &path) const; | |||||
| std::map<std::string, ge::NodePtr> node_map; | std::map<std::string, ge::NodePtr> node_map; | ||||
| // key: blob name, value: layer name and index | // key: blob name, value: layer name and index | ||||
| @@ -21,7 +21,9 @@ | |||||
| #include <google/protobuf/io/zero_copy_stream_impl.h> | #include <google/protobuf/io/zero_copy_stream_impl.h> | ||||
| #include <google/protobuf/text_format.h> | #include <google/protobuf/text_format.h> | ||||
| #include <fstream> | #include <fstream> | ||||
| #include <sys/types.h> | |||||
| #include <sys/stat.h> | |||||
| #include <fcntl.h> | |||||
| namespace ge { | namespace ge { | ||||
| void ParerSTestsUtils::ClearParserInnerCtx() { | void ParerSTestsUtils::ClearParserInnerCtx() { | ||||
| @@ -131,4 +133,14 @@ void ParerSTestsUtils::WriteProtoToBinaryFile(const google::protobuf::Message &p | |||||
| out.close(); | out.close(); | ||||
| delete[] buf; | delete[] buf; | ||||
| } | } | ||||
| void ParerSTestsUtils::WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename) { | |||||
| const int32_t fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 384U); | |||||
| if (fd >= 0) { | |||||
| google::protobuf::io::FileOutputStream output(fd); | |||||
| google::protobuf::TextFormat::Print(proto, &output); | |||||
| output.Close(); | |||||
| close(fd); | |||||
| } | |||||
| } | |||||
| } // namespace ge | } // namespace ge | ||||
| @@ -31,6 +31,7 @@ class ParerSTestsUtils { | |||||
| static MemBuffer* MemBufferFromFile(const char *path); | static MemBuffer* MemBufferFromFile(const char *path); | ||||
| static bool ReadProtoFromText(const char *file, google::protobuf::Message *message); | static bool ReadProtoFromText(const char *file, google::protobuf::Message *message); | ||||
| static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename); | static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename); | ||||
| static void WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename); | |||||
| }; | }; | ||||
| } // namespace ge | } // namespace ge | ||||
| @@ -228,6 +228,25 @@ TEST_F(STestCaffeParser, acl_caffe_parser) { | |||||
| caffe_op_map.clear(); | caffe_op_map.clear(); | ||||
| ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), parser_params, graph); | ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), parser_params, graph); | ||||
| EXPECT_EQ(ret, GRAPH_FAILED); | EXPECT_EQ(ret, GRAPH_FAILED); | ||||
| { | |||||
| proto.set_name("empty_layer"); | |||||
| auto &layers = *proto.add_layers(); | |||||
| layers.set_name("layers"); | |||||
| proto.clear_layer(); | |||||
| const std::string empty_layer = case_dir + "/origin_models/empty_layer.pbtxt"; | |||||
| ParerSTestsUtils::WriteProtoToTextFile(proto, empty_layer.c_str()); | |||||
| EXPECT_EQ(ge::aclgrphParseCaffe(empty_layer.c_str(), weight_file.c_str(), parser_params, graph), FAILED); | |||||
| proto.clear_layers(); | |||||
| const std::string empty_layers = case_dir + "/origin_models/empty_layers.pbtxt"; | |||||
| ParerSTestsUtils::WriteProtoToTextFile(proto, empty_layers.c_str()); | |||||
| EXPECT_EQ(ge::aclgrphParseCaffe(empty_layers.c_str(), weight_file.c_str(), parser_params, graph), FAILED); | |||||
| unlink(empty_layer.c_str()); | |||||
| unlink(empty_layers.c_str()); | |||||
| } | |||||
| } | } | ||||
| TEST_F(STestCaffeParser, modelparser_parsefrommemory_success) | TEST_F(STestCaffeParser, modelparser_parsefrommemory_success) | ||||
| @@ -21,6 +21,9 @@ | |||||
| #include <google/protobuf/io/zero_copy_stream_impl.h> | #include <google/protobuf/io/zero_copy_stream_impl.h> | ||||
| #include <google/protobuf/text_format.h> | #include <google/protobuf/text_format.h> | ||||
| #include <limits.h> | #include <limits.h> | ||||
| #include <sys/types.h> | |||||
| #include <sys/stat.h> | |||||
| #include <fcntl.h> | |||||
| namespace ge { | namespace ge { | ||||
| void ParerUTestsUtils::ClearParserInnerCtx() { | void ParerUTestsUtils::ClearParserInnerCtx() { | ||||
| @@ -131,6 +134,16 @@ void ParerUTestsUtils::WriteProtoToBinaryFile(const google::protobuf::Message &p | |||||
| delete[] buf; | delete[] buf; | ||||
| } | } | ||||
| void ParerUTestsUtils::WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename) { | |||||
| const int32_t fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 384U); | |||||
| if (fd >= 0) { | |||||
| google::protobuf::io::FileOutputStream output(fd); | |||||
| google::protobuf::TextFormat::Print(proto, &output); | |||||
| output.Close(); | |||||
| close(fd); | |||||
| } | |||||
| } | |||||
| namespace ut { | namespace ut { | ||||
| NodePtr GraphBuilder::AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt, Format format, | NodePtr GraphBuilder::AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt, Format format, | ||||
| DataType data_type, std::vector<int64_t> shape) { | DataType data_type, std::vector<int64_t> shape) { | ||||
| @@ -32,6 +32,7 @@ class ParerUTestsUtils { | |||||
| static MemBuffer* MemBufferFromFile(const char *path); | static MemBuffer* MemBufferFromFile(const char *path); | ||||
| static bool ReadProtoFromText(const char *file, google::protobuf::Message *message); | static bool ReadProtoFromText(const char *file, google::protobuf::Message *message); | ||||
| static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename); | static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename); | ||||
| static void WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename); | |||||
| }; | }; | ||||
| namespace ut { | namespace ut { | ||||
| @@ -267,10 +267,29 @@ TEST_F(UtestCaffeParser, acl_caffe_parser) { | |||||
| EXPECT_EQ(ret, GRAPH_FAILED); | EXPECT_EQ(ret, GRAPH_FAILED); | ||||
| ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), graph); | ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), graph); | ||||
| EXPECT_EQ(ret, GRAPH_FAILED); | EXPECT_EQ(ret, GRAPH_FAILED); | ||||
| caffe_op_map.clear(); | caffe_op_map.clear(); | ||||
| ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), parser_params, graph); | ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), parser_params, graph); | ||||
| EXPECT_EQ(ret, GRAPH_FAILED); | EXPECT_EQ(ret, GRAPH_FAILED); | ||||
| { | |||||
| proto.set_name("empty_layer"); | |||||
| auto &layers = *proto.add_layers(); | |||||
| layers.set_name("layers"); | |||||
| proto.clear_layer(); | |||||
| const std::string empty_layer = case_dir + "/caffe_model/empty_layer.pbtxt"; | |||||
| ParerUTestsUtils::WriteProtoToTextFile(proto, empty_layer.c_str()); | |||||
| EXPECT_EQ(ge::aclgrphParseCaffe(empty_layer.c_str(), weight_file.c_str(), parser_params, graph), FAILED); | |||||
| proto.clear_layers(); | |||||
| const std::string empty_layers = case_dir + "/caffe_model/empty_layers.pbtxt"; | |||||
| ParerUTestsUtils::WriteProtoToTextFile(proto, empty_layers.c_str()); | |||||
| EXPECT_EQ(ge::aclgrphParseCaffe(empty_layers.c_str(), weight_file.c_str(), parser_params, graph), FAILED); | |||||
| unlink(empty_layer.c_str()); | |||||
| unlink(empty_layers.c_str()); | |||||
| } | |||||
| } | } | ||||
| TEST_F(UtestCaffeParser, ParseFromMemory_success) | TEST_F(UtestCaffeParser, ParseFromMemory_success) | ||||