IniziaInizia gratis

Creating a sequential block

You decided to redesign your binary CNN model template by creating a block of convolutional layers. This will help you stack multiple layers sequentially. With this improved model, you will be able to easily design various CNN architectures.

torch and torch.nn as nn have been imported.

Questo esercizio fa parte del corso

Deep Learning for Images with PyTorch

Visualizza il corso

Istruzioni dell'esercizio

  • In the __init__() method, define a block of convolutional layers and assign it to self.conv_block.
  • In the forward() pass, pass the inputs through the convolutional block you defined.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

class BinaryImageClassification(nn.Module):
  def __init__(self):
    super(BinaryImageClassification, self).__init__()
    # Create a convolutional block
    self.conv_block = ____(
      nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1),
      nn.ReLU(),
      nn.Conv2d(16, 32, kernel_size=3, stride=1, padding=1),
      nn.ReLU(),
    )
    
  def forward(self, x):
    # Pass inputs through the convolutional block
    x = ____
    return x
Modifica ed esegui il codice