Caffe2 - C++ API
A deep learning, cross platform ML framework
helper.h
1 #pragma once
2 
3 #include "onnx/onnx_pb.h"
4 
5 #include <set>
6 #include <string>
7 #include <unordered_set>
8 
9 namespace caffe2 {
10 namespace onnx {
11 
12 using ::ONNX_NAMESPACE::AttributeProto;
13 using ::ONNX_NAMESPACE::NodeProto;
14 
15 // \brief This class generates unique dummy names
16 class DummyName {
17  public:
18  static std::string NewDummyName();
19 
20  static void Reset(const std::unordered_set<std::string>& used_names);
21 
22  static void AddName(const std::string& new_used) {
23  get_used_names().insert(new_used);
24  }
25 
26  private:
27  static std::unordered_set<std::string>& get_used_names();
28  static size_t counter_;
29 };
30 
31 inline AttributeProto MakeAttribute(
32  const std::string& name,
33  const std::vector<int64_t>& vals) {
34  AttributeProto attr;
35  attr.set_name(name);
36  for (const auto v : vals) {
37  attr.add_ints(v);
38  }
39  attr.set_type(AttributeProto::INTS);
40  return attr;
41 }
42 
43 inline AttributeProto MakeAttribute(const std::string& name, int64_t val) {
44  AttributeProto attr;
45  attr.set_name(name);
46  attr.set_i(val);
47  attr.set_type(AttributeProto::INT);
48  return attr;
49 }
50 
51 inline AttributeProto MakeAttribute(
52  const std::string& name,
53  const std::string& val) {
54  AttributeProto attr;
55  attr.set_name(name);
56  attr.set_s(val);
57  attr.set_type(AttributeProto::STRING);
58  return attr;
59 }
60 
61 NodeProto MakeNode(
62  const std::string& type,
63  const std::vector<std::string>& inputs,
64  const std::vector<std::string>& outputs,
65  const std::vector<AttributeProto>& attributes,
66  const std::string& name = "");
67 
68 inline NodeProto MakeNode(
69  const std::string& type,
70  const std::vector<std::string>& inputs,
71  const std::vector<std::string>& outputs,
72  const std::string& name = "") {
73  return MakeNode(type, inputs, outputs, {}, name);
74 }
75 
76 } // namespace onnx
77 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...