I am learning PyTorch for an image classification task, and I ran into code where someone used a PyTorch Variable()
in their function for prediction:
def predict_image(image):
image_tensor = test_transforms(image).float()
image_tensor = image_tensor.unsqueeze_(0)
input = Variable(image_tensor)
input = input.to(device)
output = model(input)
index = output.data.cpu().numpy().argmax()
return index
Why do they use Variable()
here? (even though it works fine without it.)