Caffe2 - C++ API
A deep learning, cross platform ML framework
helper.cc
1 #include "caffe2/onnx/helper.h"
2 
3 #include "caffe2/core/logging.h"
4 #include "caffe2/core/operator.h"
5 
6 namespace caffe2 { namespace onnx {
7 
8 size_t DummyName::counter_ = 0;
9 
10 std::unordered_set<std::string>& DummyName::get_used_names() {
11  static std::unordered_set<std::string> used_names;
12  return used_names;
13 }
14 
15 std::string DummyName::NewDummyName() {
16  while (true) {
17  const std::string name = caffe2::MakeString("OC2_DUMMY_", counter_++);
18  auto ret = get_used_names().insert(name);
19  if (ret.second) {
20  return name;
21  }
22  }
23 }
24 
25 void DummyName::Reset(const std::unordered_set<std::string> &used_names) {
26  auto& names = get_used_names();
27  names = used_names;
28  counter_ = 0;
29 }
30 
31 NodeProto MakeNode(
32  const std::string& type,
33  const std::vector<std::string>& inputs,
34  const std::vector<std::string>& outputs,
35  const std::vector<AttributeProto>& attributes,
36  const std::string& name) {
37  NodeProto node;
38  if (!name.empty()) {
39  node.set_name(name);
40  }
41  node.set_op_type(type);
42  for (const auto& input: inputs) {
43  node.add_input(input);
44  }
45  for (const auto& output: outputs) {
46  node.add_output(output);
47  }
48  for (const auto& attr: attributes) {
49  node.add_attribute()->CopyFrom(attr);
50  }
51  return node;
52 }
53 }}
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...