Complete the code to create a max pooling layer with a kernel size of 2.
import torch.nn as nn pool = nn.[1](kernel_size=2)
The nn.MaxPool2d layer performs max pooling, which selects the maximum value in each window of the input.
Complete the code to create an average pooling layer with a stride of 2.
import torch.nn as nn pool = nn.AvgPool2d(kernel_size=2, stride=[1])
The stride controls how far the pooling window moves. Setting stride=2 moves the window by 2 pixels each step.
Fix the error in the code to apply max pooling to input tensor x.
import torch import torch.nn as nn x = torch.randn(1, 1, 4, 4) pool = nn.MaxPool2d(kernel_size=2) output = pool([1])
The pooling layer is a function that takes the input tensor x and returns the pooled output.
Fill both blanks to create an average pooling layer with kernel size 3 and stride 1.
import torch.nn as nn pool = nn.[1](kernel_size=[2], stride=1)
Use AvgPool2d for average pooling. The kernel size is set to 3 to cover 3x3 windows.
Fill all three blanks to create a max pooling layer with kernel size 2, stride 2, and padding 0.
import torch.nn as nn pool = nn.[1](kernel_size=[2], stride=[3], padding=0)
The max pooling layer uses MaxPool2d with kernel size and stride both set to 2. Padding is zero to avoid adding extra pixels.