0
0
PyTorchml~10 mins

Kernel size, stride, padding 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 a kernel size of 3.

PyTorch
conv = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=[1])
Drag options to blanks, or click blank then click option'
A3
B5
C1
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using a kernel size too large for the input image.
Confusing kernel size with stride.
2fill in blank
medium

Complete the code to set the stride of the convolutional layer to 2.

PyTorch
conv = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3, stride=[1])
Drag options to blanks, or click blank then click option'
A2
B1
C3
D4
Attempts:
3 left
💡 Hint
Common Mistakes
Setting stride to 0 which is invalid.
Confusing stride with padding.
3fill in blank
hard

Fix the error in the code by choosing the correct padding value to keep output size same as input size with kernel size 3 and stride 1.

PyTorch
conv = torch.nn.Conv2d(in_channels=1, out_channels=1, kernel_size=3, stride=1, padding=[1])
Drag options to blanks, or click blank then click option'
A0
B3
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using padding 0 which shrinks output size.
Using padding too large which increases output size.
4fill in blank
hard

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

PyTorch
conv = torch.nn.Conv2d(in_channels=3, out_channels=6, kernel_size=[1], stride=[2])
Drag options to blanks, or click blank then click option'
A5
B1
C2
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up kernel size and stride values.
Using stride 1 when stride 2 is required.
5fill in blank
hard

Fill all three blanks to create a convolutional layer with kernel size 7, stride 1, and padding 3.

PyTorch
conv = torch.nn.Conv2d(in_channels=[1], out_channels=[2], kernel_size=[3], stride=1, padding=3)
Drag options to blanks, or click blank then click option'
A3
B6
C7
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of input or output channels.
Incorrect kernel size or padding causing size mismatch.