Is there a reason why num_batches_tracked
gets updated in BN but not in IN?
import torch
torch.__version__
# '1.13.1'
# Create a batch of 16 data points with 2 features
x = torch.randn(16, 2, 10)
InstanceNorm:
# Create an instance normalization layer with track_running_stats=True
norm_layer = torch.nn.InstanceNorm1d(2, track_running_stats=True, affine=False)
# Process the input data using the normalization layer
y = norm_layer(x)
# Print the running statistics of the layer
print(norm_layer.state_dict())
# OrderedDict([('running_mean', tensor([-0.0022, 0.0019])), ('running_var', tensor([1.0003, 1.0025])), ('num_batches_tracked', tensor(0))])
BatchNorm:
# Create an instance normalization layer with track_running_stats=True
norm_layer = torch.nn.BatchNorm1d(2, track_running_stats=True, affine=False)
# Process the input data using the normalization layer
y = norm_layer(x)
# Print the running statistics of the layer
print(norm_layer.state_dict())
# OrderedDict([('running_mean', tensor([-0.0022, 0.0019])), ('running_var', tensor([0.9972, 1.0007])), ('num_batches_tracked', tensor(1))])