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

ValueError and RuntimeError #11

Open
sgybupt opened this issue Mar 14, 2019 · 1 comment
Open

ValueError and RuntimeError #11

sgybupt opened this issue Mar 14, 2019 · 1 comment

Comments

@sgybupt
Copy link

sgybupt commented Mar 14, 2019

Hi, have you ever met this Error?

  • when i valuate my model, with shape(1, 3, 256, 256) imgTensor input, this Error raised up:
Traceback (most recent call last):
  File "/home/elaine/su/track2/Person-reID-triplet-loss-master/my_test.py", line 432, in <module>
    print(model(imgtrans))
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/elaine/su/track2/Person-reID-triplet-loss-master/model.py", line 86, in forward
    x, f = self.classifier(x)
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/elaine/su/track2/Person-reID-triplet-loss-master/model.py", line 54, in forward
    f = self.add_block(x)
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/container.py", line 91, in forward
    input = module(input)
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 45, in forward
    self._check_input_dim(input)
  File "/home/elaine/anaconda3/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 123, in _check_input_dim
    .format(input.dim()))
ValueError: expected 2D or 3D input (got 1D input)

I'm sure that the input tenor shape is (1, 3, 256, 256)
And i have changed mode of models into mode:eval()

print('-------test-----------')
model_structure = ft_net(opt.nclasses)
model = load_network(model_structure)
model = model.eval()  # Change to test mode
model.train(False)

if use_gpu:
    model = model.cuda()

with torch.no_grad():
    # predicts = extract_feature_cls(model, dataloaders['val'], mode='cls')
    # predicts = np.argmax(predicts, axis=0)
    temimg = Image.open('/home/elaine/su/track2/Market/pytorch/image_query/000001.jpg')
    imgtrans = data_transforms(temimg)
    imgtrans = imgtrans.unsqueeze(0)
    print(imgtrans.shape) # torch.Size([1, 3, 256, 256])
    imgtrans = Variable(imgtrans.cuda())
    print(model(imgtrans))
@sgybupt
Copy link
Author

sgybupt commented Mar 14, 2019

Thanks a lot for your work. i have got this.
input.shape must be at least (Batch, 3, 256, 256) Batch larger than 2

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

1 participant