Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Deep Learning for Images with PyTorch

Cursus bekijken

Oefeninstructies

  • 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 to input_dim.
  • Add the output features to the classifier's last layer.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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, ____),
)
Code bewerken en uitvoeren