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.
Latihan ini adalah bagian dari kursus
Deep Learning for Images with PyTorch
Petunjuk latihan
- Load the pre-trained VGG16 weights.
- Extract
in_featuresfrom theclassifier's first layer using.children()as a sequential block and store it asinput_dim. - Create a backbone as a sequential block using
featuresand.children(). - Print the backbone model.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# 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
____