Closed anshu1106 closed 6 years ago
This is because you didn't meet the usage condition of pytorch BN layer. You can set batch size to larger than 1 to solve this problem.
I am trying the code below. Where exactly do you want me to put BN>1. Would be really helpful if you can help.
from bpm.model.PCBModel import PCBModel model = PCBModel() checkpoint = torch.load('bpm_model_weight.pth') model.load_state_dict(checkpoint)
normalize = transforms.Normalize( mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225] ) preprocess = transforms.Compose([ transforms.Scale(256), transforms.CenterCrop(224), transforms.ToTensor(), normalize ])
img1 = Image.open('feature1/0.jpg')
img_tensor1 = preprocess(img1) imgtensor1.unsqueeze(0)
ValueError Traceback (most recent call last)
Well, here the error says ValueError: Expected more than 1 value per channel when training, got input size [1, 256, 1, 1]
. So I think you can set the model to eval
mode to allow single-image batch. So before the line fc_out1 = model(img_variable1)
in your code, you can insert this line model.eval()
.
Thanks @huanghoujing. It works.
Getting this error when trying to do a prediction ValueError: Expected more than 1 value per channel when training, got input size [1, 256, 1, 1]
Please help. Pytorch version is 0.3