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 std::string DummyName::NewDummyName() {
9  while (true) {
10  const std::string name = c10::str("OC2_DUMMY_", counter_++);
11  auto ret = used_names_.insert(name);
12  if (ret.second) {
13  return name;
14  }
15  }
16 }
17 
18 void DummyName::Reset(const std::unordered_set<std::string> &used_names) {
19  used_names_ = used_names;
20  counter_ = 0;
21 }
22 
23 ::ONNX_NAMESPACE::TypeProto ExtraTypeProto(
24  const ::ONNX_NAMESPACE::TensorProto& tensor) {
25  ::ONNX_NAMESPACE::TypeProto t;
26  auto* tensor_type = t.mutable_tensor_type();
27  tensor_type->set_elem_type(tensor.data_type());
28  auto* shape = tensor_type->mutable_shape();
29  for (const auto d : tensor.dims()) {
30  shape->add_dim()->set_dim_value(d);
31  }
32  return t;
33 }
34 
35 NodeProto MakeNode(
36  const std::string& type,
37  const std::vector<std::string>& inputs,
38  const std::vector<std::string>& outputs,
39  const std::vector<AttributeProto>& attributes,
40  const std::string& name) {
41  NodeProto node;
42  if (!name.empty()) {
43  node.set_name(name);
44  }
45  node.set_op_type(type);
46  for (const auto& input: inputs) {
47  node.add_input(input);
48  }
49  for (const auto& output: outputs) {
50  node.add_output(output);
51  }
52  for (const auto& attr: attributes) {
53  node.add_attribute()->CopyFrom(attr);
54  }
55  return node;
56 }
57 }}
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13