question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: only one element tensors can be converted to Python scalars

See original GitHub issue

When 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wait1988commented, Jul 12, 2019

Same error as you

0reactions
hedaobaishuicommented, Jul 17, 2020
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found