Each ONNX model is associated with an opset version, which defines the set of operators are supported by the model. Knowing the opset version of an ONNX model is important for compatibility reasons with ONNX runtime or deep learning framework. Also, understanding the opset version helps in interpreting the model's capabilities. This tutorial shows how to get the opset version of an ONNX model using Python.
Prepare environment
- Install the following package using
pip
:
pip install onnx
Code
In the following code, we load the ONNX model from the file into memory. We retrieve the opset version from the model metadata. It checks if the opset_import
attribute exists and retrieves the version if available, otherwise None
is set. Finally, the opset version is printed to the console.
import onnx
model = onnx.load('model.onnx')
opset_version = model.opset_import[0].version if len(model.opset_import) > 0 else None
print(opset_version)
Leave a Comment
Cancel reply