  
          batch_random = np.random.rand(self._batchsize)
          indices = np.where(batch_random < self._config.get("color_clahe_chance", 50) / 100)[0]
          if not np.any(indices):
              return batch
  
          grid_bases = np.rint(np.random.uniform(0,
                                                 self._config.get("color_clahe_max_size", 4),
                                                 size=indices.shape[0])).astype("uint8")
          contrast_adjustment = (grid_bases * (base_contrast // 2))
          grid_sizes = contrast_adjustment + base_contrast
          logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)
  
          clahes = [cv2.createCLAHE(clipLimit=2.0,  # pylint: disable=no-member
                                    tileGridSize=(grid_size, grid_size))
                    for grid_size in grid_sizes]
  
 
</s> remove         indices = np.where(batch_random < self._config.get("color_clahe_chance", 50) / 100)[0]
 </s> add         indices = np.where(batch_random < self._constants.clahe_chance)[0] </s> remove         base_contrast = self._constants["clahe_base_contrast"]
 </s> add         base_contrast = self._constants.clahe_base_contrast </s> remove             batch[idx, :, :, 0] = clahe.apply(batch[idx, :, :, 0])
        return batch
 </s> add             batch[idx, :, :, 0] = clahe.apply(batch[idx, :, :, 0], ) </s> remove         if not self.is_display:
            logger.trace("Randomly flipping image")
            randoms = np.random.rand(self._batchsize)
            indices = np.where(randoms > self._config.get("random_flip", 50) / 100)[0]
            batch[indices] = batch[indices, :, ::-1]
            logger.trace("Randomly flipped %s images of %s", len(indices), self._batchsize)
        return batch

    def warp(self, batch, to_landmarks=False, **kwargs):
 </s> add         logger.trace("Randomly flipping image")  # type: ignore
        randoms = np.random.rand(self._batchsize)
        indices = np.where(randoms > int(self._config.get("random_flip", 50)) / 100)[0]
        batch[indices] = batch[indices, :, ::-1]
        logger.trace("Randomly flipped %s images of %s",  # type: ignore
                     len(indices), self._batchsize)

    def warp(self, batch: np.ndarray, to_landmarks: bool = False, **kwargs) -> np.ndarray: </s> remove 
        Returns
        ----------
        :class:`numpy.ndarray`
            A 4-dimensional array of the same shape as :attr:`batch` with transformation applied.
 </s> add 
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
  
          batch_random = np.random.rand(self._batchsize)
          indices = np.where(batch_random < self._config.get("color_clahe_chance", 50) / 100)[0]
          if not np.any(indices):
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
            return
        grid_bases = np.random.randint(self._constants.clahe_max_size + 1,
                                       size=indices.shape[0],
                                       dtype="uint8")
        grid_sizes = (grid_bases * (base_contrast // 2)) + base_contrast
        logger.trace("Adjusting Contrast. Grid Sizes: %s", grid_sizes)  # type: ignore
  
          clahes = [cv2.createCLAHE(clipLimit=2.0,  # pylint: disable=no-member
                                    tileGridSize=(grid_size, grid_size))
                    for grid_size in grid_sizes]
  
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
 Data Augmentation update (#1263)

- lib.detected_face
    - Subclass Masks for Landmark based masks
    - Add training mask propery + methods to DetectedFace
  - lib.training_training
    - subclass TrainingDataGenerator for training and preview data
    - Split cache into own module
    - Reduce thread count to 1 to prevent image corruption + data re-use
    - Process on largest model input/output size rather than stored image size
    - Size and crop masks during caching stage
    - Implement ring buffer for data flow
    - Fix preview reload bug
  - augmentation
    - typing
    - switch color aug order
    - better initialization
    - Fix warp + landmark warp to correctly apply at different image scales
    - Slightly improved warp caching
    - Don't store whether image is_preview. Handle all data as training images implicitly
  - plugins.trainer: Typing and fixes to work with trainingdata refactor 
lib/training/augmentation.py