Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError:Dimension out of range(excepted to be in range of [-1,0],but got 1) #75

Open
aiqiangbrave opened this issue Mar 25, 2022 · 4 comments

Comments

@aiqiangbrave
Copy link

aiqiangbrave commented Mar 25, 2022

Hello,can you help me ?thank you! When I use Market data set ,report an error:

problem:
/home/waq/anaconda3/envs/re_person/bin/python /home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py
-------test-----------
/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py:182: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
config = yaml.load(stream)
Traceback (most recent call last):
File "/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py", line 204, in
gallery_feature = extract_feature(model,dataloaders['gallery'])
File "/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py", line 131, in extract_feature
x[0] = norm(x[0])
File "/home/waq/Downloads/ai/re_person/code/DG-Net/DG-Net-master/test_2label.py", line 109, in norm
fnorm = torch.norm(f, p=2, dim=1, keepdim=True)
File "/home/waq/anaconda3/envs/re_person/lib/python3.6/site-packages/torch/functional.py", line 1337, in norm
return _VF.norm(input, p, _dim, keepdim=keepdim) # type: ignore
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Process finished with exit code 1

Thank you!

@nikky4D
Copy link

nikky4D commented Apr 20, 2022

Check the size of the matrix/vector in x[0], if it has a 1 in the batch dimension, after squeeze in norm() function, this reduces to a vector which is problematic for the norm

@layumi
Copy link
Contributor

layumi commented Apr 20, 2022

Yes @aiqiangbrave

It is due to the batch size = 1

You could use

if len(x.shape) ==2:
    x = x.unsqueeze(0)

Something like that.

@aiqiangbrave
Copy link
Author

aiqiangbrave commented Apr 21, 2022 via email

@aiqiangbrave
Copy link
Author

Check the size of the matrix/vector in x[0], if it has a 1 in the batch dimension, after squeeze in norm() function, this reduces to a vector which is problematic for the norm

okok,thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants