class_docstr: Base class for `neural (or range) augmentation <https://arxiv.org/abs/2212.10553>`_
class_docstr_tok: ["Base","class","for","`","neural","(","or","range",")","augmentation","<","https",":","\/\/arxiv.org\/abs\/2212.10553",">","`","_"]
code: def forward(self, x: Tensor, *args, **kwargs) -> Tensor:
      batch_size, in_channels, in_height, in_width = x.shape
  
      # Randomly apply augmentation to 50% of the samples
      n_aug_samples = max(1, (batch_size // 2))
  
      # shuffle the order of augmentations
      random.shuffle(self.aug_fns)
  
      for aug_fn in self.aug_fns:
          # select 50% samples for augmentation
          sample_ids = torch.randperm(
              n=batch_size, dtype=torch.long, device=x.device
          )[:n_aug_samples]
          x_aug = torch.index_select(x, dim=0, index=sample_ids)
          # apply augmentation
          x_aug = aug_fn(x=x_aug)
          # copy augmented samples to tensor
          x = torch.index_copy(x, dim=0, source=x_aug, index=sample_ids)
  
      # clip the values so that they are between 0 and 1
      x = torch.clip(x, min=0.0, max=1.0)
      return x
  
imports: import argparse
  import random
  from typing import List, Optional
  import torch
  from torch import Tensor, nn
  from cvnets.misc.common import parameter_list
  from cvnets.neural_augmentor.utils.neural_aug_utils import Clip, FixedSampler, UniformSampler, random_brightness, random_contrast, random_noise
  from utils import logger
label_desc: Use image node_id 10 for calling the BaseNeuralAugmentor obj's underlying member method code with example usage: obj.forward(x) and returns: x