3 #include "caffe2/core/common.h" 4 #include "caffe2/core/tensor.h" 5 #include "caffe2/onnx/helper.h" 6 #include "caffe2/proto/caffe2_pb.h" 7 #include "onnx/onnx_pb.h" 10 #include <unordered_map> 17 using ::ONNX_NAMESPACE::AttributeProto;
18 using ::ONNX_NAMESPACE::GraphProto;
19 using ::ONNX_NAMESPACE::ModelProto;
20 using ::ONNX_NAMESPACE::NodeProto;
21 using ::ONNX_NAMESPACE::TensorProto;
24 using ConvertedResult =
25 std::pair<std::vector<NodeProto>, std::vector<TensorProto>>;
29 CAFFE2_API std::unordered_map<std::string, std::string> SsaRewrite(
30 caffe2::NetDef* init_net,
31 caffe2::NetDef* pred_net);
33 ::ONNX_NAMESPACE::TensorProto::DataType Caffe2TypeToOnnxType(
34 caffe2::TensorProto::DataType t);
37 using SpecialOpConverter = ConvertedResult (
OnnxExporter::*)(
38 const caffe2::OperatorDef&,
39 const std::unordered_map<std::string, caffe2::TensorShape>&);
44 dummy_ = std::shared_ptr<DummyName>(dummy, [](
DummyName*) {});
46 dummy_ = std::make_shared<DummyName>();
50 ConvertedResult Caffe2OpToOnnxNodes(
51 const caffe2::OperatorDef& def,
52 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
54 void InitOpToTensorProto(
const caffe2::OperatorDef& def, TensorProto* tensor);
56 ConvertedResult CommonCaffe2OpToOnnxNodes(
const caffe2::OperatorDef& def);
58 ConvertedResult CreateArgMaxMinOpNodes(
59 const caffe2::OperatorDef& def,
60 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
62 ConvertedResult CreateBinaryElementwiseOpNodes(
63 const caffe2::OperatorDef& def,
64 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
66 ConvertedResult CreateCastNodes(
67 const caffe2::OperatorDef& def,
68 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
70 ConvertedResult CreateElementwiseLinearNodes(
71 const caffe2::OperatorDef& def,
72 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
74 ConvertedResult CreateConvPoolNodes(
75 const caffe2::OperatorDef& def,
76 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
78 ConvertedResult CreateGemmNodes(
79 const caffe2::OperatorDef& def,
80 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
82 ConvertedResult CreateReshapeNodes(
83 const caffe2::OperatorDef& def,
84 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
86 ConvertedResult CreateSliceNodes(
87 const caffe2::OperatorDef& def,
88 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
90 ConvertedResult CreateChannelShuffleNodes(
91 const caffe2::OperatorDef& def,
92 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
94 ConvertedResult CreateReduceMeanNodes(
95 const caffe2::OperatorDef& def,
96 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
98 ConvertedResult CreateConcatNodes(
99 const caffe2::OperatorDef& def,
100 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
102 ConvertedResult CreateMergeDimNodes(
103 const caffe2::OperatorDef& def,
104 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
106 ConvertedResult CreateLrnNodes(
107 const caffe2::OperatorDef& def,
108 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
110 ConvertedResult CreateUpsampleNodes(
111 const caffe2::OperatorDef& def,
112 const std::unordered_map<std::string, caffe2::TensorShape>& shapes);
119 void CopyCaffe2ArgToOnnxAttr(
120 AttributeProto* attr,
121 const std::string& op_type,
125 const std::unordered_map<std::string, std::string>& get_renamed_operators()
127 const std::unordered_map<std::string, std::string>& get_renamed_attrs()
const;
129 unordered_map<std::string, std::unordered_map<std::string, std::string>>&
130 get_per_op_renamed_attrs()
const;
131 const std::unordered_map<std::string, OnnxExporter::SpecialOpConverter>&
132 get_special_operators()
const;
135 std::shared_ptr<DummyName> dummy_;
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...