Classifier block
Your next task is to create a classifier block that will replace the original VGG16 classifier. You decide to use a block with two fully connected layers with a ReLU activation in between.
The vgg_model
and input_dim
you defined in the last exercise are available in your workspace, and torch
and torchvision.models
have been imported.
This exercise is part of the course
Deep Learning for Images with PyTorch
Exercise instructions
- Create a variable
num_classes
with the number of classes assuming you're dealing with detecting cats and dogs only. - Create a sequential block using
nn.Sequential
. - Create a linear layer with
in_features
set toinput_dim
. - Add the output features to the classifier's last layer.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a variable with the number of classes
____
# Create a sequential block
classifier = ____(
# Create a linear layer with input features
____(____, 512),
nn.ReLU(),
# Add the output dimension to the classifier
nn.Linear(512, ____),
)