ONNX Import and Export
The Open Neural Network Exchange (ONNX) AI model format is a generic AI model format supported by many AI vendors that allows sharing AI deep neural net models between different AI platforms and tools. The MyCaffe AI Platform allows you to easily export MyCaffe models to *.onnx files and import ONNX models from *.onnx files into MyCaffe models.
This section describes how to both import from and export to the *.onnx file format using the OnnxControl available on NUGET.
Importing ONNX to MyCaffe
The MyCaffeConversionControl is used to import and export *.onnx files. In this section we show how to import the ‘bvlcalexnet-9.onnx‘ AlexNet model from the ONNX model zoo.
Before importing, first download the AlexNet model from the ONNX model zoo located here.
To import, first create an instance of the MyCaffeConversionControl which handles converting the ONNX file and converting it into the MyCaffe model descriptor and byte array of weights. For the conversion, just call the MyCaffeConversionControl.ConvertOnnxToMyCaffeFromFile method.
Once completed, both the model descriptor and weights are returned in an instance of the MyCaffeModelData object.
Exporting from MyCaffe to ONNX
Exporting a MyCaffe model to ONNX *.onnx file is just as simple.
To export, we first create an instance of the MyCaffeConversionControl which handles converting the MyCaffe model descriptor and byte array of weights to the ONNX file.
To carry out the conversion, load your model descriptor and model weights into a MyCaffeModelData object and pass the object along with the ONNX file name to the MyCaffeConversionControl.ConvertMyCaffeToOnnxFile method.
Using the MyCaffeConversionControl opens up MyCaffe to a large number of pre-trained models available in the ONNX model zoo.
In addition, converting your MyCaffe models into the ONNX file format opens up your trained models to a growing set of tools used for fast inference and deployment.
To try this out yourself, just add the MyCaffe NUGET package to your project, and build and run the OnnxExample MyCaffe sample available on GitHub.