Complete the code to create a 2D convolutional layer with 3 input channels and 16 output channels.
conv_layer = torch.nn.Conv2d([1], 16, kernel_size=3, stride=1, padding=1)
The first argument to Conv2d is the number of input channels. For example, an RGB image has 3 channels.
Complete the code to apply the convolutional layer to the input tensor.
output = conv_layer([1])The convolutional layer is applied to the input tensor to produce the output feature map.
Fix the error in the code to correctly initialize the convolutional layer with a 5x5 kernel.
conv_layer = torch.nn.Conv2d(3, 16, kernel_size=[1], stride=1, padding=2)
The kernel size should be 5 to create a 5x5 filter. Padding of 2 keeps the output size same as input.
Fill both blanks to create a feature map by applying a convolution and then a ReLU activation.
conv_layer = torch.nn.Conv2d(3, 8, kernel_size=3, padding=1) output = conv_layer([1]) activated_output = torch.nn.functional.[2](output)
The input tensor is passed to the convolutional layer, then ReLU activation is applied to introduce non-linearity.
Fill all three blanks to create a simple CNN block: convolution, activation, and max pooling.
conv = torch.nn.Conv2d(1, [1], kernel_size=3, padding=1) x = conv([2]) x = torch.nn.functional.[3](x) x = torch.nn.functional.max_pool2d(x, 2)
The convolution outputs 5 channels, input_image is the input tensor, and ReLU activation is applied before max pooling.