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.
Bu egzersiz
Deep Learning for Images with PyTorch
kursunun bir parçasıdırEgzersiz talimatları
- In the
__init__()method, define a block of convolutional layers and assign it toself.conv_block. - In the
forward()pass, pass the inputs through the convolutional block you defined.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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