meetps / pytorch-semseg

Semantic Segmentation Architectures Implemented in PyTorch
https://meetshah.dev/semantic-segmentation/deep-learning/pytorch/visdom/2017/06/01/semantic-segmentation-over-the-years.html
MIT License
3.39k stars 798 forks source link

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

Open Galto2000 opened 6 years ago

Galto2000 commented 6 years ago

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

FengLoveBella commented 6 years ago

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

jiaxiaochong commented 6 years ago

visual studio 2017 also meet that problem...

scyoyo commented 6 years ago

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.

Galto2000 commented 6 years ago

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'])) 
wisdomk commented 5 years ago

that didn't work, any further suggestions?

ChengYeung1222 commented 5 years ago

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