MulaiMulai sekarang secara gratis

Adding a new convolutional layer

Your project lead provided you with a new CNN model. Let's take a look at the model's architecture and append a new convolutional layer to it.

The model is available as CNNModel. The packages torch and torch.nn as nn have been imported.

Latihan ini adalah bagian dari kursus

Deep Learning for Images with PyTorch

Lihat Kursus

Petunjuk latihan

  • Instantiate a model from the CNNModel class and access the convolutional layers.
  • Create a new convolutional layer with in_channels equal to existing layer's out_channels, out_channels set to 32, and stride and padding both set to 1, and a kernel_size of 3; assign it to conv2.
  • Append the new layer to the model, calling it "conv2".

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Create a model
model = ____
print("Original model: ", model)

# Create a new convolutional layer
conv2 = ____

# Append the new layer to the model
model.____(____)
print("Extended model: ", model)
Edit dan Jalankan Kode