ValueError: only one element tensors can be converted to Python scalars
See original GitHub issueWhen I try transfer a mobilenet_v2 model from pytorch to onnx, ValueRrror has appeared. ValueError: only one element tensors can be converted to Python scalars How can I sovle it? Here is my code:
import torch
import torchvision
import torch.onnx
from torch.autograd import Variable
# An instance of your model
model = torchvision.models.mobilenet_v2(pretrained=True)
print(model)
x = torch.randn(1, 3, 224, 224,requires_grad=True)
# Export the model
torch_out = torch.onnx._export(model, x, "mobilenet_v2.onnx", export_params=True)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top Results From Across the Web
ValueError: only one element tensors can be converted to ...
shape(). But trying to convert my list into an array, I got a ValueError: only one element tensors can be converted to Python...
Read more >only one element tensors can be converted to Python scalars
ValueError : only one element tensors can be converted to Python scalars. You try and convert the output of your model to a...
Read more >only one element tensors can be converted to Python scalars ...
This happens in the training loop. ValueError: only one element tensors can be converted to Python scalars ...
Read more >only one element tensors can be converted to python scalars ...
One of the main benefits of converting a tensor to a Python scalar is that it can make your code more concise and...
Read more >ValueError: only one element tensors can be converted to ...
ValueError : only one element tensors can be converted to Python scalars.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Same error as you
Thanks @spandantiwari