Aan de slagGa gratis aan de slag

Loading a pre-trained model

You are building an application to label images from the social media. This task requires high accuracy and speed. You are going to use a pre-trained ResNet18 model to infer image classes.

Deze oefening maakt deel uit van de cursus

Deep Learning for Images with PyTorch

Cursus bekijken

Oefeninstructies

  • Import resnet18 and ResNet18_Weights from torchvision.models.
  • Instantiate the model using resnet18(), setting the weights parameter to weights.
  • Set model to the evaluation mode.
  • Initialize the input transforms and assign them to transform.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import resnet18 model
from torchvision.models import ____

# Initialize model with default weights
weights = ResNet18_Weights.DEFAULT
model = ____

# Set model to evaluation mode
model.____

# Initialize the transforms
transform = ____
Code bewerken en uitvoeren