0
0
PyTorchml~10 mins

nn.Conv2d layers in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a 2D convolutional layer with 3 input channels and 16 output channels.

PyTorch
conv_layer = nn.Conv2d([1], 16, kernel_size=3)
Drag options to blanks, or click blank then click option'
A1
B3
C16
D32
Attempts:
3 left
💡 Hint
Common Mistakes
Using the number of output channels as the first argument.
Confusing kernel size with input channels.
2fill in blank
medium

Complete the code to apply the convolutional layer to the input tensor.

PyTorch
output = conv_layer([1])
Drag options to blanks, or click blank then click option'
Ainput_tensor
Bconv_layer
Coutput
Dnn.Conv2d
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the layer itself instead of the input tensor.
Using the output variable before it is defined.
3fill in blank
hard

Fix the error in the code by completing the missing argument for padding.

PyTorch
conv_layer = nn.Conv2d(3, 16, kernel_size=3, padding=[1])
Drag options to blanks, or click blank then click option'
A1
B0
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using padding 0 causes output size to shrink.
Using padding larger than needed causes unexpected output size.
4fill in blank
hard

Fill both blanks to create a convolutional layer with stride 2 and kernel size 5.

PyTorch
conv_layer = nn.Conv2d(3, 32, kernel_size=[1], stride=[2])
Drag options to blanks, or click blank then click option'
A5
B2
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing stride with padding.
Using kernel size 3 instead of 5.
5fill in blank
hard

Fill all three blanks to create a Conv2d layer with 1 input channel, 10 output channels, kernel size 3, padding 1.

PyTorch
conv_layer = nn.Conv2d([1], [2], kernel_size=[3], padding=1)
Drag options to blanks, or click blank then click option'
A1
B10
C3
D16
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up input and output channels.
Forgetting to set padding to 1 for same output size.