  
      def _random_clahe(self, batch):
          """ Randomly perform Contrast Limited Adaptive Histogram Equalization on
          a batch of images """
          base_contrast = self._constants["clahe_base_contrast"]
  
          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
 
</s> remove     def _random_clahe(self, batch):
 </s> add     def _random_clahe(self, batch: np.ndarray) -> None: </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         if not self.is_display:
            logger.trace("Augmenting color")
            batch = batch_convert_color(batch, "BGR2LAB")
            batch = self._random_clahe(batch)
            batch = self._random_lab(batch)
            batch = batch_convert_color(batch, "LAB2BGR")
 </s> add         logger.trace("Augmenting color")  # type: ignore
        batch = batch_convert_color(batch, "BGR2LAB")
        self._random_lab(batch)
        self._random_clahe(batch)
        batch = batch_convert_color(batch, "LAB2BGR") </s> remove             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)
 </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 </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:
        base_contrast = self._constants.clahe_base_contrast
  
      def _random_clahe(self, batch):
          """ Randomly perform Contrast Limited Adaptive Histogram Equalization on
          a batch of images """
        base_contrast = self._constants.clahe_base_contrast
  
          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
keep keep keep keep 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