text: import torch
  import torchvision.transforms as transforms
  
  normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                   std=[0.229, 0.224, 0.225])
  
  class PCALighting(object):
      """Lighting noise(AlexNet - style PCA - based noise)"""
      def __init__(self, alphastd, eigval, eigvec):
          self.alphastd = alphastd
          self.eigval = eigval
          self.eigvec = eigvec
  
      def __call__(self, img):
          if self.alphastd == 0:
              return img
          alpha = img.new().resize_(3).normal_(0, self.alphastd)
          rgb = self.eigvec.type_as(img).clone()\
              .mul(alpha.view(1, 3).expand(3, 3))\
              .mul(self.eigval.view(1, 3).expand(3, 3))\
              .sum(1).squeeze()
          return img.add(rgb.view(3, 1, 1).expand_as(img))
  
  
  imagenet_pca = {
      'eigval': torch.Tensor([0.2175, 0.0188, 0.0045]),
      'eigvec': torch.Tensor([
          [-0.5675,  0.7192,  0.4009],
          [-0.5808, -0.0045, -0.8140],
          [-0.5836, -0.6948,  0.4203],
      ])
  }
  
  def strong_train_preprocess(img_size):
      trans = transforms.Compose([
          transforms.RandomResizedCrop(img_size),
          transforms.RandomHorizontalFlip(),
          transforms.ColorJitter(brightness=0.4, saturation=0.4, hue=0.4),
          transforms.ToTensor(),
          PCALighting(0.1, imagenet_pca['eigval'], imagenet_pca['eigvec']),
          normalize,
      ])
      print('---------------------- strong dataaug!')
      return trans
  
  def standard_train_preprocess(img_size):
      trans = transforms.Compose([
          transforms.RandomResizedCrop(img_size),
          transforms.RandomHorizontalFlip(),
          transforms.ToTensor(),
          normalize,
      ])
      print('---------------------- weak dataaug!')
      return trans
  
  def val_preprocess(img_size):
      trans = transforms.Compose([
          transforms.Resize(256),
          transforms.CenterCrop(img_size),
          transforms.ToTensor(),
          normalize,
      ])
      return trans
  
  class AverageMeter(object):
      """Computes and stores the average and current value"""
      def __init__(self, name, fmt=':f'):
          self.name = name
          self.fmt = fmt
          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 __str__(self):
          fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})'
          return fmtstr.format(**self.__dict__)
  
  
  class ProgressMeter(object):
      def __init__(self, num_batches, meters, prefix=""):
          self.batch_fmtstr = self._get_batch_fmtstr(num_batches)
          self.meters = meters
          self.prefix = prefix
  
      def display(self, batch):
          entries = [self.prefix + self.batch_fmtstr.format(batch)]
          entries += [str(meter) for meter in self.meters]
          print('\t'.join(entries))
  
      def _get_batch_fmtstr(self, num_batches):
          num_digits = len(str(num_batches // 1))
          fmt = '{:' + str(num_digits) + 'd}'
          return '[' + fmt + '/' + fmt.format(num_batches) + ']'
  
  
  def accuracy(output, target, topk=(1,)):
      """Computes the accuracy over the k top predictions for the specified values of k"""
      with torch.no_grad():
          maxk = max(topk)
          batch_size = target.size(0)
  
          _, pred = output.topk(maxk, 1, True, True)
          pred = pred.t()
          correct = pred.eq(target.view(1, -1).expand_as(pred))
  
          res = []
          for k in topk:
              correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
              res.append(correct_k.mul_(100.0 / batch_size))
          return res
  
  
  def read_hdf5(file_path):
      import h5py
      import numpy as np
      result = {}
      with h5py.File(file_path, 'r') as f:
          for k in f.keys():
              value = np.asarray(f[k])
              result[str(k).replace('+', '/')] = value
      print('read {} arrays from {}'.format(len(result), file_path))
      f.close()
      return result
  
  def model_load_hdf5(model:torch.nn.Module, hdf5_path, ignore_keys='stage0.'):
      weights_dict = read_hdf5(hdf5_path)
      for name, param in model.named_parameters():
          print('load param: ', name, param.size())
          if name in weights_dict:
              np_value = weights_dict[name]
          else:
              np_value = weights_dict[name.replace(ignore_keys, '')]
          value = torch.from_numpy(np_value).float()
          assert tuple(value.size()) == tuple(param.size())
          param.data = value
      for name, param in model.named_buffers():
          print('load buffer: ', name, param.size())
          if name in weights_dict:
              np_value = weights_dict[name]
          else:
              np_value = weights_dict[name.replace(ignore_keys, '')]
          value = torch.from_numpy(np_value).float()
          assert tuple(value.size()) == tuple(param.size())
          param.data = value