code: def recalculate_bn_statistics(model, batchsize):
      train = CamVidDataset(split="train")
      it = chainer.iterators.SerialIterator(
          train, batchsize, repeat=False, shuffle=False
      )
      bn_avg_mean = defaultdict(np.float32)
      bn_avg_var = defaultdict(np.float32)
  
      n_iter = 0
      for batch in it:
          imgs, _ = concat_examples(batch)
          model(model.xp.array(imgs))
          for name, link in model.namedlinks():
              if name.endswith("_bn"):
                  bn_avg_mean[name] += link.avg_mean
                  bn_avg_var[name] += link.avg_var
          n_iter += 1
  
      for name, link in model.namedlinks():
          if name.endswith("_bn"):
              link.avg_mean = bn_avg_mean[name] / n_iter
              link.avg_var = bn_avg_var[name] / n_iter
  
      return model
  
file_path: chainercv/examples/segnet/train.py
imports: import argparse
  from collections import defaultdict
  import os
  import chainer
  import numpy
  from chainer.dataset import concat_examples
  from chainer.datasets import TransformDataset
  from chainer import iterators
  from chainer import optimizers
  from chainer import training
  from chainer.training import extensions
  from chainercv.datasets import camvid_label_names
  from chainercv.datasets import CamVidDataset
  from chainercv.extensions import SemanticSegmentationEvaluator
  from chainercv.links import PixelwiseSoftmaxClassifier
  from chainercv.links import SegNetBasic
label_desc: Use image node_id 1 for calling a global function with example usage: recalculate_bn_statistics(model, batchsize) and returns: model