-
Notifications
You must be signed in to change notification settings - Fork 10
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
Error on single image inference, thanks #11
Comments
My current workaround solution is to use multiple images in a batch. However, it might be better to figure out how to solve the single image issue. In addition, the model produces a softmax output with 10 element for a single image, because I am using the AVA model. How can we compute a single score for an image? Thank you. |
|
I got it, thanks a lot. |
@junyongyou hi could you solve this issue without using the dataloader? For now I am doing
because it seems that the problem is that the BatchNorm1d is in training mode, although we set the whole model to eval. I am sure there is nicer solution. I guess the BatchNorm should be created when creating the TargetNet and then the forward pass just calls it. |
@woshidandan Ok my solution doesn't work because it throws some wrong predictions. I would need the single image inference without dataloader for converting the model to onnx. Any ideas? |
There are some sub-models that are not in eval mode even the whole model is set to eval. Thus, I don't know how to solve the problem. |
@junyongyou 关于single image inference,想问下你这边解决了吗? |
I have tried to use the model to do aesthetics assessment on a single image, and below is my code snippet:
`
class IAA:
def init(self, model_file, weights_path):
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
self.init_model(model_file, weights_path)
normalize = transforms.Normalize(mean=IMAGE_NET_MEAN, std=IMAGE_NET_STD)
self.transform = transforms.Compose([
transforms.ToTensor(),
normalize
])
if name == 'main':
weights_path = r'.\weights\SRCC_758_LCC_765.pth'
model_file = r'.\weights\resnet18_places365.pth.tar'
image_path = r'.\samples\00000.png'
iaa = IAA(model_file, weights_path)
score = iaa.inference(image_path)
`
However, I got an error: ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 1]).
It seems this is a reported error when using batchnorm on a single image (batch size =1), see here (https://discuss.pytorch.org/t/error-expected-more-than-1-value-per-channel-when-training/26274/67). However, it was suggested that adding model.eval() can solve the problem. As you can see, I used model.eval(), but still got the error.
Did you happen to encounter to this error? If so, how did you solve it? Thanks a lot.
The text was updated successfully, but these errors were encountered: