Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input_size is not defined in Convert_ONNX #81

Open
anrahman4 opened this issue Aug 17, 2022 · 3 comments
Open

input_size is not defined in Convert_ONNX #81

anrahman4 opened this issue Aug 17, 2022 · 3 comments
Assignees

Comments

@anrahman4
Copy link

[Enter feedback here]
I am trying to follow this guide, and I wanted to export the PyTorch model or the .pth file to .onnx. However, when constructing the dummy_input, one of the paramters is input_size, which is not defined anywhere in the tutorial as a variable.

As a result, I am unable to convert the .pth file to a onnx file. Please correct the code so that I can properly do the conversion.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@anrahman4
Copy link
Author

I have found a solution:

Replace dummy_input = torch.randn(1, input_size, requires_grad=True) with dummy_input = torch.randn(1, 3, 32, 32, requires_grad=True)

torch.randn is used to create a randomized tensor to feed into the model. The first parameter is the batch size, it is set to 1 here but I believe it can be set to other values as well. The second parameter is number of channels. In this tutorial, the first convolutional neural network layer has 3 channels, so it is expecting an input tensor to have the same value, and thus it is set to 3.

Lastly, the last two parameters are height and width. Since it is using images in the CIFAR10 dataset, the height and width are both 32.

If you then run the Convert_ONNX function, you should get the proper output.

@markp3rry
Copy link

I can confirm this solution works :)

@djebel-amila
Copy link

djebel-amila commented Jan 30, 2023

Thanks @anrahman4 , glad I found this ;-)
Anyone has got leads on how to prepare their own data to replace that from this tutorial?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants