ONNX files have the ability to specify opset as the version when the file was created. The operators that can be used and their functions (operator properties) change depending on the value of opset. Unless otherwise specified, it is treated as the latest opset.
Some Deep Learning tools include a routine to check the opset value in the ONNX file and see if it can handle it. If it is rejected by the confirmation routine there, you need to lower the opset and recreate the ONNX file.
https://github.com/onnx/onnx/blob/master/docs/Operators.md
If you look here, you can check the version supported by each operator. For example, you can see that there are versions 1, 6 and 13 in ABS, and bfloat 16 is added as a type that can be used in ABS in 13.
How to specify the opset depends on the converter, but in most cases you can specify the opset version as an argument. This is the specification method when using keras2onnx.
import tensorflow
import onnx
import keras2onnx
model_file = 'foo.h5'
#Set opset and save
keras_model = tensorflow.keras.models.load_model(model_file)
onnx_model = keras2onnx.convert_keras(keras_model, 'foo1', target_opset=9)
By specifying target_opset, an ONNX file with opset = 9 will be generated.
When you know that the operator you are using is clearly compatible with the old operator (if you are not using the new features) and you want to specify the opset value in the ONNX file just to pass the converter check. There is also. In this case, you can edit the ONNX file directly to change the opset.
As a continuation of the above source
onnx_model.opset_import[0].version = 10
with open("op10.onnx", 'wb') as f:
f.write(onnx_model.SerializeToString())
A value is specified directly for opset_import [0] .version in the onnx file. 10 is used as the opset when saved.
The quickest way is to print onnx directly as a string with print (onnx_model) and the value will be displayed as opset_import towards the end.
opset_import {
domain: ""
version: 10
}
opset is set to 10.
Recommended Posts