Repository navigation
Expand file tree
/
Copy pathchecker.h
More file actions
111 lines (96 loc) · 2.9 KB
/
Copy pathchecker.h
File metadata and controls
111 lines (96 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma once
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include "onnx/defs/function.h"
#include "onnx/defs/schema.h"
#include "onnx/onnx-operators_pb.h"
#include "onnx/onnx_pb.h"
#include "onnx/string_utils.h"
namespace ONNX_NAMESPACE {
namespace checker {
class ValidationError final : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
const char* what() const noexcept override {
if (!expanded_message_.empty()) {
return expanded_message_.c_str();
}
return std::runtime_error::what();
}
void AppendContext(const std::string& context) {
expanded_message_ = ONNX_NAMESPACE::MakeString(
std::runtime_error::what(), "\n\n==> Context: ", context);
}
private:
std::string expanded_message_;
};
#define fail_check(...) \
throw ONNX_NAMESPACE::checker::ValidationError( \
ONNX_NAMESPACE::MakeString(__VA_ARGS__));
class CheckerContext final {
public:
int get_ir_version() const {
return ir_version_;
}
void set_ir_version(int v) {
ir_version_ = v;
}
const std::unordered_map<std::string, int>& get_opset_imports() const {
return opset_imports_;
}
void set_opset_imports(std::unordered_map<std::string, int> imps) {
opset_imports_ = std::move(imps);
}
bool is_main_graph() const {
return is_main_graph_;
}
void set_is_main_graph(bool is_main_graph) {
is_main_graph_ = is_main_graph;
}
void set_schema_registry(const ISchemaRegistry* schema_registry) {
schema_registry_ = schema_registry;
}
const ISchemaRegistry* get_schema_registry() const {
return schema_registry_;
}
void set_model_dir(const std::string& model_dir){
model_dir_ = model_dir;
}
std::string get_model_dir() const {
return model_dir_;
}
explicit CheckerContext() : ir_version_(-1) {}
private:
int ir_version_;
std::unordered_map<std::string, int> opset_imports_;
bool is_main_graph_ = true;
const ISchemaRegistry* schema_registry_ = OpSchemaRegistry::Instance();
std::string model_dir_;
};
struct LexicalScopeContext final {
std::unordered_set<std::string> output_names;
};
using IR_VERSION_TYPE = decltype(Version::IR_VERSION);
void check_value_info(const ValueInfoProto& value_info, const CheckerContext&);
void check_tensor(const TensorProto& tensor, const CheckerContext&);
void check_attribute(
const AttributeProto& attr,
const CheckerContext&,
const LexicalScopeContext&);
void check_node(
const NodeProto& node,
const CheckerContext&,
const LexicalScopeContext&);
void check_graph(
const GraphProto& graph,
const CheckerContext&,
const LexicalScopeContext&);
void check_function(
const FunctionProto& function,
const CheckerContext&,
const LexicalScopeContext&);
void check_model(const ModelProto& model);
void check_model(const std::string& model_path);
} // namespace checker
} // namespace ONNX_NAMESPACE