TRANSFER LEARNING FOR COMPUTER VISION TUTORIAL Question

Hi everyone! I’m new to Pytorch and was going over a great tutorial. (Transfer Learning for Computer Vision Tutorial — PyTorch Tutorials 1.9.0+cu102 documentation). But I’m having trouble figuring out how to make a simple inference. For example, all I want to do after the model is done training I want to input a test image and get back a result with some probabilities. Thanks!!

Lets assume you have loaded you model as ‘model’

  • Load you image to the kernel ( I recomment using PIL)
from PIL import Image
image = Image.open('path')
  • Perform image transforms
import torchvision.transforms as tf
toTensor = tf.Compose([
    tf.ToTensor()
])
image_input = toTensor(image)
image_input = image_input.resize(1,3,1500,1500)
image_input.shape
  • Predict
with torch.no_grad():
            preds = torch.sigmoid(model(image_input))
            preds = (preds > 0.19).float()
  • Plot the results

I’ve done similar stuff in a project maybe this might help