Get startedGet started for free

Pre-trained model backbone

It's time to build an R-CNN architecture! You will use the vgg16 pre-trained model's backbone for feature extraction. You also remember to store the output shape of the backbone which will serve as the input shape for the subsequent blocks: the classifier and the box regressor.

torch, torchvision, torch.nn as nn have been imported. The model has been imported as vgg16 with the weights stored in VGG16_Weights.

This exercise is part of the course

Deep Learning for Images with PyTorch

View Course

Exercise instructions

  • Load the pre-trained VGG16 weights.
  • Extract in_features from the classifier's first layer using .children() as a sequential block and store it as input_dim.
  • Create a backbone as a sequential block using features and .children().
  • Print the backbone model.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Load pretrained weights
vgg_model = vgg16(weights=____)

# Extract the input dimension
input_dim = nn.Sequential(*list(vgg_model.classifier.____()))[0].____

# Create a backbone with convolutional layers
backbone = nn.Sequential(*list(____))

# Print the backbone model
____
Edit and Run Code