Complete the code to create a batch normalization layer for 10 features.
import torch.nn as nn batch_norm = nn.BatchNorm[1](10)
The nn.BatchNorm1d layer is used for batch normalization on 1-dimensional feature vectors, such as in fully connected layers or 1D conv outputs.
Complete the code to apply batch normalization to input tensor x.
output = batch_norm([1])You apply the batch normalization layer to the input tensor x by calling it like a function.
Fix the error in the code to correctly initialize batch normalization for 3D input.
batch_norm = nn.BatchNorm[1](16)
For 3D inputs like videos or volumetric data, nn.BatchNorm3d is the correct batch normalization layer.
Fill both blanks to create a batch normalization layer and apply it to input tensor x.
batch_norm = nn.BatchNorm[1]([2]) output = batch_norm(x)
BatchNorm2d is used for 2D convolutional outputs with 16 channels.
Fill all three blanks to create a batch normalization layer, apply it to x, and get the mean of the output.
batch_norm = nn.BatchNorm[1]([2]) output = batch_norm([3]) mean_val = output.mean()
BatchNorm1d is created for 20 features, applied to input tensor x, then the mean of the output is computed.