0
0
PyTorchml~10 mins

nn.MaxPool2d and nn.AvgPool2d 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 max pooling layer with a kernel size of 2.

PyTorch
import torch.nn as nn

pool = nn.[1](kernel_size=2)
Drag options to blanks, or click blank then click option'
AConv2d
BAvgPool2d
CMaxPool2d
DLinear
Attempts:
3 left
💡 Hint
Common Mistakes
Using nn.AvgPool2d instead of nn.MaxPool2d
Using nn.Conv2d which is for convolution, not pooling
2fill in blank
medium

Complete the code to create an average pooling layer with a stride of 2.

PyTorch
import torch.nn as nn

pool = nn.AvgPool2d(kernel_size=2, stride=[1])
Drag options to blanks, or click blank then click option'
A1
B3
C4
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Setting stride to 1 causes overlapping pooling windows
Using stride larger than kernel size can skip input regions
3fill in blank
hard

Fix the error in the code to apply max pooling to input tensor x.

PyTorch
import torch
import torch.nn as nn

x = torch.randn(1, 1, 4, 4)
pool = nn.MaxPool2d(kernel_size=2)
output = pool([1])
Drag options to blanks, or click blank then click option'
Ax
Bpool
Cnn
Dtorch
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the pooling layer itself instead of the input tensor
Passing the torch module instead of the input tensor
4fill in blank
hard

Fill both blanks to create an average pooling layer with kernel size 3 and stride 1.

PyTorch
import torch.nn as nn

pool = nn.[1](kernel_size=[2], stride=1)
Drag options to blanks, or click blank then click option'
AAvgPool2d
BMaxPool2d
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using MaxPool2d instead of AvgPool2d
Setting kernel size to 2 instead of 3
5fill in blank
hard

Fill all three blanks to create a max pooling layer with kernel size 2, stride 2, and padding 0.

PyTorch
import torch.nn as nn

pool = nn.[1](kernel_size=[2], stride=[3], padding=0)
Drag options to blanks, or click blank then click option'
AMaxPool2d
B2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using AvgPool2d instead of MaxPool2d
Setting stride or kernel size incorrectly
Adding padding when not needed