Complete the code to create a simple convolutional layer in a neural network.
conv_layer = nn.Conv2d(in_channels=3, out_channels=16, kernel_size=[1])
The kernel size defines the size of the filter that slides over the image. A kernel size of 5 is commonly used to capture features effectively.
Complete the code to add a ReLU activation after a convolutional layer.
model = nn.Sequential(
nn.Conv2d(3, 16, 5),
[1]()
)ReLU is a common activation function that helps the model learn non-linear features effectively.
Fix the error in the code to correctly flatten the output before a fully connected layer.
x = x.view(x.size(0), [1])
Using -1 lets PyTorch automatically calculate the correct size for flattening all dimensions except the batch size.
Fill both blanks to create a dictionary comprehension that maps layer names to their output sizes if size is greater than 100.
layer_sizes = {name: size for name, size in layers.items() if size [1] 100 and 'conv' [2] name}The comprehension filters layers with size greater than 100 and names containing 'conv'.
Fill all three blanks to create a dictionary of layer outputs where output size is less than 50 and layer name contains 'pool'.
filtered_outputs = { [1]: [2] for [3] in outputs.items() if [2] < 50 and 'pool' in [1] }The comprehension iterates over (name, output) pairs, filters outputs less than 50, and checks if 'pool' is in the layer name.