So I am trying to use a vgg16 for simple image classification. So I converted PIL image to tensor, then to variable and passed to model but still get “not 3d tensor error”. What could be the problem?
edit: nevermind, image was 3d but to forward it you need to pass it as 4d tensor
def transform_image(pil_image):
loader = transforms.Compose([
transforms.Scale(imsize),  # scale imported image
transforms.ToTensor()])  # transform it into a torch tensor
return loader(pil_image)
def load_model():
return models.vgg16(pretrained=True)  # todo load finetunned model only for hotdogs
def get_label(path):
one_image = load_image(path)
image_tensor = transform_image(one_image)
image_as_variable = Variable(image_tensor)
print(image_as_variable)
model = load_model()
label = model.forward(image_as_variable)
return label
def load_image(path):
return Image.open(path)