The ONNX network's output 'output' dimensions should be non-negative
See original GitHub issueAsk a Question
Question
I trained a CycleGAN and imported it to onnx format.
When I import the onnx model to the runtime(Snap Lens Studio),
I got the error like this and cannot import it.
Resource import for /Users/youjin/Downloads/latest_net_G (1).onnx failed: The ONNX network's output '625' dimensions should be non-negative
From this post, I assumed that I got the error cuz the output node does not know its shape.
(when I print the
output.shape
or use torchsummary
, it shows the output shape clearly)
I used dynamic_axes
of torch.onnx.export
like the snippet below.
When I open it with Netron, it seems to show the right shape, but it still gives the same error on Snap Lens Studio.
I am thinking of using resize at the end of the model now. I’d like to hear any opinion on solving this situation. Even I am not sure I am on the right track.
Further information
-
Relevant Area (e.g. model usage, backend, best practices, converters, shape_inference, version_converter, training, test, operators): runtime error
-
Is this issue related to a specific model?
Model name (e.g. mnist): CycleGAN Model opset (e.g. 7): 11
Notes
Any additional information, code snippets.
net.eval()
net.cuda()
RESOLUTION = 512
batch_size = 1
input_shape = (3, RESOLUTION, RESOLUTION) # in my case its 512
export_onnx_file = load_filename[:-4]+".onnx"
save_path = os.path.join(self.save_dir, export_onnx_file)
input_names = ["input"]
output_names = ["output"]
random_input = torch.randn(1, 3, RESOLUTION, RESOLUTION, dtype=torch.float32)
torch.onnx.export(net, random_input, save_path,
input_names = input_names, output_names = output_names,
opset_version = 11,)
dynamic_axes={
'output' : {
0:'1',
1:'3',
2:'512',
3:'512'
}})
onnx.save(onnx.shape_inference.infer_shapes(onnx.load(save_path)), save_path)
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
I came back with an update. It turns out that Snap Lens Studio has some limitations with onnx models, so it would be safe to use their provided models only. I found the CycleGAN model from Snap Research, and I could import their model without any error.
@jcwchen Thanks for checking the model! Now I am assured it is now the model problem, so I can switch my direction. Let me come back if I have any updates or some other onnx-related questions.