class_docstr: Randomly apply MixUp to the provided batch and targets.
  The class implements the data augmentations as described in the paper
  `"mixup: Beyond Empirical Risk Minimization" <https://arxiv.org/abs/1710.09412>`_.
  
  Args:
      num_classes (int): number of classes used for one-hot encoding.
      p (float): probability of the batch being transformed. Default value is 0.5.
      alpha (float): hyperparameter of the Beta distribution used for mixup.
          Default value is 1.0.
      inplace (bool): boolean to make this transform inplace. Default set to False.
class_docstr_tok: ["Randomly","apply","MixUp","to","the","provided","batch","and","targets",".","The","class","implements","the","data","augmentations","as","described","in","the","paper","`","``","mixup",":","Beyond","Empirical","Risk","Minimization","''","<","https",":","\/\/arxiv.org\/abs\/1710.09412",">","`","_",".","Args",":","num_classes","(","int",")",":","number","of","classes","used","for","one-hot","encoding",".","p","(","float",")",":","probability","of","the","batch","being","transformed",".","Default","value","is","0.5.","alpha","(","float",")",":","hyperparameter","of","the","Beta","distribution","used","for","mixup",".","Default","value","is","1.0.","inplace","(","bool",")",":","boolean","to","make","this","transform","inplace",".","Default","set","to","False","."]
docstr: Args:
      batch (Tensor): Float tensor of size (B, C, H, W)
      target (Tensor): Integer tensor of size (B, )
  
  Returns:
      Tensor: Randomly transformed batch.
docstr_tok: ["Args",":","batch","(","Tensor",")",":","Float","tensor","of","size","(","B",",","C",",","H",",","W",")","target","(","Tensor",")",":","Integer","tensor","of","size","(","B",",",")","Returns",":","Tensor",":","Randomly","transformed","batch","."]
code: def forward(
      self, batch: Tensor, target: Tensor
  ) -> Tuple[Tensor, Tensor]:
      """
      Args:
          batch (Tensor): Float tensor of size (B, C, H, W)
          target (Tensor): Integer tensor of size (B, )
  
      Returns:
          Tensor: Randomly transformed batch.
      """
      if batch.ndim != 4:
          raise ValueError(f"Batch ndim should be 4. Got {batch.ndim}")
      if target.ndim != 1:
          raise ValueError(
              f"Target ndim should be 1. Got {target.ndim}"
          )
      if not batch.is_floating_point():
          raise TypeError(
              f"Batch dtype should be a float tensor. Got {batch.dtype}."
          )
      if target.dtype != torch.int64:
          raise TypeError(
              f"Target dtype should be torch.int64. Got {target.dtype}"
          )
  
      if not self.inplace:
          batch = batch.clone()
          target = target.clone()
  
      if target.ndim == 1:
          target = torch.nn.functional.one_hot(
              target, num_classes=self.num_classes
          ).to(dtype=batch.dtype)
  
      if torch.rand(1).item() >= self.p:
          return batch, target
  
      # It's faster to roll the batch by one instead of shuffling it to create image pairs
      batch_rolled = batch.roll(1, 0)
      target_rolled = target.roll(1, 0)
  
      # Implemented as on mixup paper, page 3.
      lambda_param = float(
          torch._sample_dirichlet(
              torch.tensor([self.alpha, self.alpha])
          )[0]
      )
      batch_rolled.mul_(1.0 - lambda_param)
      batch.mul_(lambda_param).add_(batch_rolled)
  
      target_rolled.mul_(1.0 - lambda_param)
      target.mul_(lambda_param).add_(target_rolled)
  
      return batch, target
  
file_path: vision/references/classification/transforms.py
imports: import math
  from typing import Tuple
  import torch
  from presets import get_module
  from torch import Tensor
  from torchvision.transforms import functional
label_desc: Use image node_id 2 for calling the RandomMixUp obj's underlying member method code with example usage: obj.forward(batch, target) and returns: batch,  target, batch,  target