3 #include "caffe2/core/common.h" 4 #include "onnx/onnx_pb.h" 8 #include <unordered_set> 13 using ::ONNX_NAMESPACE::AttributeProto;
14 using ::ONNX_NAMESPACE::NodeProto;
19 std::string NewDummyName();
21 void Reset(
const std::unordered_set<std::string>& used_names);
23 void AddName(
const std::string& new_used) {
24 used_names_.insert(new_used);
28 std::unordered_set<std::string> used_names_;
32 ::ONNX_NAMESPACE::TypeProto ExtraTypeProto(
33 const ::ONNX_NAMESPACE::TensorProto& tensor);
35 inline AttributeProto MakeAttribute(
36 const std::string& name,
37 const std::vector<int64_t>& vals) {
40 for (
const auto v : vals) {
43 attr.set_type(AttributeProto::INTS);
47 inline AttributeProto MakeAttribute(
48 const std::string& name,
49 const std::vector<float>& vals) {
52 for (
const auto v : vals) {
55 attr.set_type(AttributeProto::FLOATS);
59 inline AttributeProto MakeAttribute(
const std::string& name, int64_t val) {
63 attr.set_type(AttributeProto::INT);
67 inline AttributeProto MakeAttribute(
68 const std::string& name,
69 const std::string& val) {
73 attr.set_type(AttributeProto::STRING);
77 inline AttributeProto MakeAttribute(
78 const std::string& name,
79 ::ONNX_NAMESPACE::TensorProto& val) {
82 attr.mutable_t()->CopyFrom(val);
83 attr.set_type(AttributeProto::TENSOR);
88 ::ONNX_NAMESPACE::TensorProto MakeTensor(
90 const std::vector<T>& v,
91 const ::ONNX_NAMESPACE::TensorProto_DataType& data_type_) {
92 ::ONNX_NAMESPACE::TensorProto ret;
94 ret.add_dims(v.size());
95 ret.set_data_type(data_type_);
96 ret.mutable_raw_data()->assign(
97 reinterpret_cast<const char*>(v.data()), v.size() *
sizeof(
T));
101 CAFFE2_API NodeProto MakeNode(
102 const std::string& type,
103 const std::vector<std::string>& inputs,
104 const std::vector<std::string>& outputs,
105 const std::vector<AttributeProto>& attributes,
106 const std::string& name =
"");
108 inline NodeProto MakeNode(
109 const std::string& type,
110 const std::vector<std::string>& inputs,
111 const std::vector<std::string>& outputs,
112 const std::string& name =
"") {
113 return MakeNode(type, inputs, outputs, {}, name);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...