pytorch-semseg icon indicating copy to clipboard operation
pytorch-semseg copied to clipboard

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

Open Galto2000 opened this issue 7 years ago • 6 comments

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

Galto2000 avatar Jan 31 '18 18:01 Galto2000

@Galto2000 I encountered the same error, did you solve it?

FengLoveBella avatar Feb 26 '18 03:02 FengLoveBella

visual studio 2017 also meet that problem...

jiaxiaochong avatar Apr 17 '18 12:04 jiaxiaochong

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.

scyoyo avatar Apr 24 '18 22:04 scyoyo

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'])) 

Galto2000 avatar Jul 02 '18 20:07 Galto2000

that didn't work, any further suggestions?

wisdomk avatar Mar 01 '19 10:03 wisdomk

Use .squeeze() or .unsqueeze() builtin function to subtract or add ndims to 1 respectively. This worked in my program.

ChengYeung1222 avatar Sep 05 '19 05:09 ChengYeung1222