TL;DR
--Library and application summary to convert to ONNX or check the contents of ONNX (will be updated at any time)
-[1. ONNX Version and Opset](# 1-onnx version and opset) -[2. Conversion between machine learning frameworks](# 2-Conversion between machine learning frameworks) - 2.1. MMdnn - 2.2. ONNXMLTools - 2.3. keras2onnx - 2.4. WinMLTools -[3. ONNX version conversion](# 3-onnx version conversion) - 3.1. ONNX Version Converter -[4. Confirmation](# 4-Confirmation) - 4.1. Netron
――Basically, proceed to work after creating a virtual environment
Example in Anaconda
conda create -n mmdnn python=3.6
1.1. Version
(investigating...)
1.2. Opset
(investigating...)
ONNX versioning https://github.com/onnx/onnx/blob/master/docs/Versioning.md ONNX Version Converter https://github.com/onnx/onnx/blob/master/docs/VersionConverter.md ONNX Runtime version compatibility documentation https://github.com/microsoft/onnxruntime/blob/master/docs/Versioning.md ONNX version and Windows build https://docs.microsoft.com/ja-jp/windows/ai/windows-ml/onnx-versions
2.1. MMdnn
https://github.com/Microsoft/MMdnn
MMdnn is a comprehensive, cross-framework tool for transforming, visualizing and diagnosing deep learning (DL) models. "MM" is an abbreviation for model management, and "dnn" is an acronym for deep neural network.
Reference: https://github.com/Microsoft/MMdnn
Reprinted from (as of July 7, 2020): https://github.com/Microsoft/MMdnn
pip install mmdnn
--Other modules are required according to the conversion format. If you want to convert keras format (* .karas, * .h5), keras, tensorflow, etc.
mmconvert -sf keras -iw <keras HDF5 file(*.h5)> -df onnx -om <Output ONNX file(*.onnx)>
Reference: https://arakan-pgm-ai.hatenablog.com/entry/2019/03/01/090000
2.1.6. Tips
-** When raise ValueError ('No model found in config file.')
Is displayed in the load_model_from_hdf5 method **
It seems that it is displayed when the saved keras format is only weighting.
There is information that the workaround was improved by using model.save ()
instead of model.save_weights ()
when saving.
reference: - AssertionError · Issue #324 · microsoft/MMdnn -[About weight / model storage and loading in Keras](https://intellectual-curiosity.tokyo/2019/07/04/keras%E3%81%AB%E3%81%8A%E3%81%91% E3% 82% 8B% E9% 87% 8D% E3% 81% BF% EF% BC% 8F% E3% 83% A2% E3% 83% 87% E3% 83% AB% E3% 81% AE% E4% BF% 9D% E5% AD% 98% E3% 80% 81% E8% AA% AD% E3% 81% BF% E8% BE% BC% E3% 81% BF% E3% 81% AB% E3% 81% A4% E3% 81% 84 /)
2.2. ONNXMLTools
https://github.com/onnx/onnxmltools https://pypi.org/project/onnxmltools/
ONNXMLTools allows you to convert models from various machine learning toolkits to ONNX.
Source: https://github.com/onnx/onnxmltools
--Keras (wrapper of keras2onnx converter) --Tensorflow (wrapper of tf2onnx converter) --scikit-learn (wrapper of skl2onnx converter)
Reprinted from (as of July 7, 2020): https://github.com/onnx/onnxmltools
2.3. keras2onnx
https://github.com/onnx/keras-onnx
The keras2onnx model converter allows you to convert Keras models to ONNX model format. Initially, the Keras converter was developed in the onnxmltools project, but the development of the Keras2onnx converter has been moved to a separate repository to support more types of Keras models and reduce the complexity of mixing multiple converters. ..
Source: https://github.com/onnx/keras-onnx
Also, [WinMLTool](# 12-winmltools) wraps the call to keras2onnx.
2.4. WinMLTools
Convert various machine learning models to ONNX and use them in Windows ML (fast inference environment for Windows) A tool to enable you.
https://docs.microsoft.com/ja-jp/windows/ai/windows-ml/convert-model-winmltools
WinMLTools allows you to convert machine learning models created by various training frameworks to ONNX. This is an extension of ONNXMLTools and TF2ONNX to convert the model to ONNX for use in Windows ML.
Source: https://docs.microsoft.com/ja-jp/windows/ai/windows-ml/convert-model-winmltools
Reprinted from (as of July 7, 2020): https://docs.microsoft.com/ja-jp/windows/ai/windows-ml/convert-model-winmltools
3.1. ONNX Version Converter
https://github.com/onnx/onnx/blob/master/docs/VersionConverter.md
Tutorial showing an example of how to upgrade and downgrade an ONNX model to a new target opset https://github.com/onnx/tutorials/blob/master/tutorials/ExportModelFromPyTorchForWinML.md
The ONNX API provides a library for converting ONNX models between different opset versions. This allows developers and data scientists to upgrade their existing ONNX models to newer versions or downgrade their models to older versions of the ONNX specification. Version converters can be called using the C ++ or Python API. A tutorial is also provided that shows an example of how to upgrade and downgrade an ONNX model to a new target opset.
Source: https://docs.microsoft.com/ja-jp/windows/ai/windows-ml/onnx-versions
4.1. Netron
https://github.com/lutzroeder/netron
Install with Winget
winget install -e --id LutzRoeder.Netron
You can check the ONNX version from the Model Properties button on the upper left.
** Confirmation example 1 **
--ONNX file format version is v6 --Two INPUTS, three OUTPUTS
** Confirmation example 2 **
--ONNX file format version is v7 --Two INPUTS and three OUTPUTS (no difference from Confirmation Example 1)