class_docstr: This implements the mixup data augmentation in the paper
  "mixup: Beyond Empirical Risk Minimization" (https://arxiv.org/abs/1710.09412)
class_docstr_tok: ["This","implements","the","mixup","data","augmentation","in","the","paper","''","mixup",":","Beyond","Empirical","Risk","Minimization","''","(","https",":","\/\/arxiv.org\/abs\/1710.09412",")"]
code: def _mix_pair(self, x):
      batch_size = len(x)
      lam_batch, use_cutmix = self._params_per_elem(batch_size // 2)
      x_orig = (
          x.clone()
      )  # need to keep an unmodified original for mixing source
      for i in range(batch_size // 2):
          j = batch_size - i - 1
          lam = lam_batch[i]
          if lam != 1.0:
              if use_cutmix[i]:
                  (yl, yh, xl, xh), lam = cutmix_bbox_and_lam(
                      x[i].shape,
                      lam,
                      ratio_minmax=self.cutmix_minmax,
                      correct_lam=self.correct_lam,
                  )
                  x[i][:, yl:yh, xl:xh] = x_orig[j][:, yl:yh, xl:xh]
                  x[j][:, yl:yh, xl:xh] = x_orig[i][:, yl:yh, xl:xh]
                  lam_batch[i] = lam
              else:
                  x[i] = x[i] * lam + x_orig[j] * (1 - lam)
                  x[j] = x[j] * lam + x_orig[i] * (1 - lam)
  
      lam_batch = torch.cat((lam_batch, lam_batch.flip(0)))
      return lam_batch.to(x).unsqueeze(1)
  
imports: import collections.abc
  import math
  from typing import Any, Dict, Optional, Tuple
  import numpy
  import torch
  from torch.distributions.beta import Beta
label_desc: Use image node_id 5 for calling the MixupTransform obj's underlying member method code with example usage: obj._mix_pair(x) and returns: lam_batch