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.

AttributeError: 'torch.FloatTensor' object has no attribute 'ndim'

See original GitHub issue

Howdy folks

relatively new to Python, numpy, PyTorch (come from C++ and Matlab).

I am using CUDA 9.1, Python 3.6, Torch 0.3.0.post4, running on Ubuntu 16.04 LTS and I am starting off as follows:

python train.py --arch segnet --dataset pascal --visdom True

And I get the error below when I want to invoke visdom (i.e. when I don’t include --visdom True, I don’t have this issue).

  File "/home/bart/anaconda3/envs/pytorch-semseg/lib/python3.6/site-packages/visdom/__init__.py", line 438, in line
    assert Y.ndim == 1 or Y.ndim == 2, 'Y should have 1 or 2 dim'
AttributeError: 'torch.FloatTensor' object has no attribute 'ndim'

Any suggestions anyone?

Thanks in advance

Galto

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Galto2000commented, Jul 2, 2018

Sorry for the late response. I was not able to resolve it personally, but I did the thing scyoyo suggested and that fixed it. I also had to change some dimensions, as shown below:

    if args.visdom:
        vis = visdom.Visdom()

        loss_window = vis.line(X=torch.zeros((2,)).numpy(),
                           Y=torch.zeros((2,)).numpy(),
                           opts=dict(xlabel='minibatches',
                                     ylabel='Loss',
                                     title='Training Loss',
                                     legend=['Loss'])) 
1reaction
scyoyocommented, Apr 24, 2018

I also encounter this problem, change the .cpu() to .numpy() would solve that. Not sure whether it’s because the code of visdom is updated from torch tensor to numpy array.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: 'torch.FloatTensor' object has no attribute 'ndim ...
I am using CUDA 9.1, Python 3.6, Torch 0.3.0.post4, ... AttributeError: 'torch.FloatTensor' object has no attribute 'ndim' #63.
Read more >
pytorch torch.Tensor object has not ndim attribute
I have one variable that is a torch.Tensor. When I try a_tensor.ndim it throws an error: "Attribute Error Tensor object has no attribute...
Read more >
How to fix following error 'torch.FloatTensor' object has no ...
And this error means data and label already are tensors in GPU and you cloning them again into GPU using .to() method.
Read more >
ImageCleaner causes AttributeError: 'Tensor' object has no ...
When I get to the 'Cleaning Up' section in the lesson the cell fails to run and gives me a AttributeError: 'Tensor' object...
Read more >
Attributeerror: 'Tensor' Object Has No Attribute 'To_Sparse'
Running a simple program using Tensorflow import tensorflow as tf tf.add1 AttributeError: 'Tensor' object has no attribute 'numpy' see full image Igel helps ......
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