How do we save a onnx model converted from caffe2 in python?
I followed the tutorial https://github.com/onnx/tutorials/blob/master/tutorials/Caffe2OnnxExport.ipynb to export a caffe2 squeezenet model to onnx, but how do we save the onnx model to a file in python? Suppose I cannot use a shell script and have to use python.
@jjiang2cal did you find the answer?
Add the below line in your code to save the model
onnx.save(onnx_model, 'path/to/the/model.onnx')
Hi, anyone knows in which version was save() introduced? I'm seeing "AttributeError: module 'onnx' has no attribute 'save'"
I'm on:
(py36) PS C:\Users\dimension> conda list onnx
// packages in environment at C:\Users\xxx\conda\envs\py36:
//
// Name Version Build Channel
onnx 1.1.1 py36_0 conda-forge
I'm running in Conda:
(py36) PS C:\Users\dimension> python .\re_generate.py
Traceback (most recent call last):
File ".\re_generate.py", line 9, in <module>
onnx.save(new_model, 'test_3_withDynamicDimension.onnx')
AttributeError: module 'onnx' has no attribute 'save'
Here's my script:
import onnx
from google.protobuf.json_format import Parse
json_file = 'test.onnx.json'
with open(json_file, 'r') as f:
json_str = f.read()
# Convert String to a new onnx model
new_model = Parse(json_str, onnx.ModelProto())
onnx.save(new_model, 'test.onnx')
Hi, anyone knows in which version was save() introduced? I'm seeing "AttributeError: module 'onnx' has no attribute 'save'"
I'm on:
(py36) PS C:\Users\dimension> conda list onnx // packages in environment at C:\Users\xxx\conda\envs\py36: // // Name Version Build Channel onnx 1.1.1 py36_0 conda-forgeI'm running in Conda:
(py36) PS C:\Users\dimension> python .\re_generate.py Traceback (most recent call last): File ".\re_generate.py", line 9, in <module> onnx.save(new_model, 'test_3_withDynamicDimension.onnx') AttributeError: module 'onnx' has no attribute 'save'Here's my script:
import onnx from google.protobuf.json_format import Parse json_file = 'test.onnx.json' with open(json_file, 'r') as f: json_str = f.read() # Convert String to a new onnx model new_model = Parse(json_str, onnx.ModelProto()) onnx.save(new_model, 'test.onnx')
Ok, I unblocked myself by running the same scripts outside conda, pip installing onnx is good enough to run my script.