IniziaInizia gratis

Multi-class classification model

With a template for a binary classification model in place, you can now build on it to design a multi-class classification model. The model should handle different numbers of classes via a parameter, allowing you to tailor the model to a specific multi-class classification task in the future.

The packages torch and torch.nn as nn have been imported. All image sizes are 64x64 pixels.

Questo esercizio fa parte del corso

Deep Learning for Images with PyTorch

Visualizza il corso

Istruzioni dell'esercizio

  • Define the __init__ method including self and num_classes as parameters.
  • Create a fully connected layer with the input size of 16*32*32 and the number of classes num_classes as output.
  • Create an activation function softmax with dim=1.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

class MultiClassImageClassifier(nn.Module):
  
    # Define the init method
    def ____(____, ____):
        super(MultiClassImageClassifier, self).__init__()
        self.conv1 = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
        self.relu = nn.ReLU()
        self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2)
        self.flatten = nn.Flatten()

        # Create a fully connected layer
        self.fc = ____(____, ____)
        
        # Create an activation function
        self.softmax = ____(____)
Modifica ed esegui il codice