Browse Source

!526 Fix error code of layer invalid

Merge pull request !526 from 张晓昆/trunk_ai
pull/528/head
i-robot Gitee 3 years ago
parent
commit
bca55b40df
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 82 additions and 6 deletions
  1. +13
    -4
      parser/caffe/caffe_parser.cc
  2. +2
    -0
      parser/caffe/caffe_parser.h
  3. +13
    -1
      tests/st/parser_st_utils.cc
  4. +1
    -0
      tests/st/parser_st_utils.h
  5. +19
    -0
      tests/st/testcase/test_caffe_parser.cc
  6. +13
    -0
      tests/ut/parser/parser_ut_utils.cc
  7. +1
    -0
      tests/ut/parser/parser_ut_utils.h
  8. +20
    -1
      tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc

+ 13
- 4
parser/caffe/caffe_parser.cc View File

@@ -1435,6 +1435,18 @@ Status CaffeModelParser::SaveDataLayerTops(const domi::caffe::LayerParameter &la
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) {
bool has_error = false;
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);

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),


+ 2
- 0
parser/caffe/caffe_parser.h View File

@@ -313,6 +313,8 @@ class PARSER_FUNC_VISIBILITY CaffeModelParser : public domi::ModelParser {

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;

// key: blob name, value: layer name and index


+ 13
- 1
tests/st/parser_st_utils.cc View File

@@ -21,7 +21,9 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <fstream>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

namespace ge {
void ParerSTestsUtils::ClearParserInnerCtx() {
@@ -131,4 +133,14 @@ void ParerSTestsUtils::WriteProtoToBinaryFile(const google::protobuf::Message &p
out.close();
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

+ 1
- 0
tests/st/parser_st_utils.h View File

@@ -31,6 +31,7 @@ class ParerSTestsUtils {
static MemBuffer* MemBufferFromFile(const char *path);
static bool ReadProtoFromText(const char *file, google::protobuf::Message *message);
static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename);
static void WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename);
};
} // namespace ge



+ 19
- 0
tests/st/testcase/test_caffe_parser.cc View File

@@ -228,6 +228,25 @@ TEST_F(STestCaffeParser, acl_caffe_parser) {
caffe_op_map.clear();
ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), parser_params, graph);
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)


+ 13
- 0
tests/ut/parser/parser_ut_utils.cc View File

@@ -21,6 +21,9 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

namespace ge {
void ParerUTestsUtils::ClearParserInnerCtx() {
@@ -131,6 +134,16 @@ void ParerUTestsUtils::WriteProtoToBinaryFile(const google::protobuf::Message &p
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 {
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) {


+ 1
- 0
tests/ut/parser/parser_ut_utils.h View File

@@ -32,6 +32,7 @@ class ParerUTestsUtils {
static MemBuffer* MemBufferFromFile(const char *path);
static bool ReadProtoFromText(const char *file, google::protobuf::Message *message);
static void WriteProtoToBinaryFile(const google::protobuf::Message &proto, const char *filename);
static void WriteProtoToTextFile(const google::protobuf::Message &proto, const char *filename);
};

namespace ut {


+ 20
- 1
tests/ut/parser/testcase/caffe_parser_testcase/caffe_parser_unittest.cc View File

@@ -267,10 +267,29 @@ TEST_F(UtestCaffeParser, acl_caffe_parser) {
EXPECT_EQ(ret, GRAPH_FAILED);
ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), graph);
EXPECT_EQ(ret, GRAPH_FAILED);
caffe_op_map.clear();
ret = ge::aclgrphParseCaffe(model_file.c_str(), weight_file.c_str(), parser_params, graph);
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)


Loading…
Cancel
Save