Caffe2 has built-in support for ONNX. This includes support for exporting Caffe2 models to ONNX format and importing ONNX models directly for inference in Caffe2. C++ source files related to Caffe2's support of ONNX can be found in the onnx directory in the Caffe2 source code. Python source files that provide the frontend and backend support for ONNX can be found in the python/onnx directory in the Caffe2 source code.
The onnx/onnx_exporter.h and onnx/onnx_exporter.cc contain the definitions necessary to export a Caffe2 model to ONNX format. Support for exporting from Caffe2 to ONNX includes details such as the mapping from Caffe2 to ONNX for operators, data types, and transformations of data.
For example, in onnx/onnx_exporter.cc we find the following mapping of some Caffe2 operators to ONNX operators:
const std::unordered_map<std::string, std::string>...