If someone still needs this, we wrote up a small script to compute a population statistics:

  
      github.com
  
  
    warmspringwinds/pytorch-segmentation-detection/blob/master/pytorch_segmentation_detection/utils/batchnorm.py 42
import torch
import torch.nn as nn


## A module dedicated to computing the true population statistics
## after the training is done following the original Batch norm paper

# Example of usage:

# Note: you might want to traverse the dataset a couple of times to get
# a better estimate of the population statistics
# Make sure your trainloader has shuffle=True and drop_last=True

# net.apply(adjust_bn_layers_to_compute_populatin_stats)
# for i in range(10): 
#     with torch.no_grad():
#         for batch_idx, (inputs, targets) in enumerate(trainloader):
#             _ = net(inputs.cuda())
# net.apply(restore_original_settings_of_bn_layers)



  This file has been truncated. show original