text: import json
  from pathlib import Path
  from collections import OrderedDict
  
  
  class AverageMeter(object):
      """Computes and stores the average and current value"""
  
      def __init__(self):
          self.reset()
  
      def reset(self):
          self.val = 0
          self.avg = 0
          self.sum = 0
          self.count = 0
  
      def update(self, val, n=1):
          self.val = val
          self.sum += val * n
          self.count += n
          self.avg = self.sum / self.count
  
  
  def count_params(model):
      return sum(p.numel() for p in model.parameters() if p.requires_grad)
  
  
  def read_json(fname):
      fname = Path(fname)
      with fname.open('rt') as handle:
          return json.load(handle, object_hook=OrderedDict)
  
  
  def write_json(content, fname):
      fname = Path(fname)
      with fname.open('wt') as handle:
          json.dump(content, handle, indent=4, sort_keys=False)