              ``True`` if the mask should be returned zipped otherwise ``False``
  
          Returns
          -------
          :class:`numpy.ndarray` or zipped array
              The mask as a single channel image of the given :attr:`size` dimension. If
              :attr:`as_zip` is ``True`` then the :class:`numpy.ndarray` will be contained within a
              zipped container
          """
          # TODO Face mask generation from landmarks
          logger.trace("size: %s, area: %s, aligned: %s, dilation: %s, blur_kernel: %s, as_zip: %s",
                       size, area, aligned, dilation, blur_kernel, as_zip)
          areas = dict(mouth=[slice(48, 60)], eyes=[slice(36, 42), slice(42, 48)])
 
</s> remove         logger.trace("size: %s, area: %s, aligned: %s, dilation: %s, blur_kernel: %s, as_zip: %s",
                     size, area, aligned, dilation, blur_kernel, as_zip)
        areas = dict(mouth=[slice(48, 60)], eyes=[slice(36, 42), slice(42, 48)])
        if aligned:
            face = AlignedFace(self.landmarks_xy, centering=centering, size=size)
            landmarks = face.landmarks
            size = (size, size)
        else:
            landmarks = self.landmarks_xy
        points = [landmarks[zone] for zone in areas[area]]  # pylint:disable=unsubscriptable-object
        mask = _LandmarksMask(size, points, dilation=dilation, blur_kernel=blur_kernel)
        retval = mask.get(as_zip=as_zip)
        return retval
 </s> add         logger.trace("area: %s, dilation: %s", area, dilation)  # type: ignore
        areas = dict(mouth=[slice(48, 60)], eye=[slice(36, 42), slice(42, 48)])
        points = [self.aligned.landmarks[zone]
                  for zone in areas[area]]

        lmmask = LandmarksMask(points,
                               storage_size=self.aligned.size,
                               storage_centering=self.aligned.centering,
                               dilation=dilation)
        lmmask.set_blur_and_threshold(blur_kernel=blur_kernel)
        lmmask.generate_mask(
            self.aligned.adjusted_matrix,
            self.aligned.interpolators[1])
        return lmmask.mask

    def store_training_masks(self,
                             masks: List[Optional[np.ndarray]],
                             delete_masks: bool = False) -> None:
        """ Concatenate and compress the given training masks and store for retrieval.

        Parameters
        ----------
        masks: list
            A list of training mask. Must be all be uint-8 3D arrays of the same size in
            0-255 range
        delete_masks: bool, optional
            ``True`` to delete any of the :class:`Mask` objects owned by this detected face. Use to
            free up unrequired memory usage. Default: ``False``
        """
        if delete_masks:
            del self.mask
            self.mask = {}

        valid = [msk for msk in masks if msk is not None]
        if not valid:
            return
        combined = np.concatenate(valid, axis=-1)
        self._training_masks = (compress(combined), combined.shape)

    def get_training_masks(self) -> Optional[np.ndarray]:
        """ Obtain the decompressed combined training masks.

        Returns
        -------
        :class:`numpy.ndarray`
            A 3D array containing the decompressed training masks as uint8 in 0-255 range if
            training masks are present otherwise ``None``
        """
        if not self._training_masks:
            return None
        return np.frombuffer(decompress(self._training_masks[0]),
                             dtype="uint8").reshape(self._training_masks[1]) </s> remove class _LandmarksMask():  # pylint:disable=too-few-public-methods
    """ Create a single channel mask from aligned landmark points.

    size: tuple
        The (height, width) shape tuple that the mask should be returned as
    points: list
        A list of landmark points that correspond to the given shape tuple to create
        the mask. Each item in the list should be a :class:`numpy.ndarray` that a filled
        convex polygon will be created from
    dilation: int, optional
        The amount of dilation to apply to the mask. `0` for none. Default: `0`
    blur_kernel: int, optional
        The kernel size for applying gaussian blur to apply to the mask. `0` for none. Default: `0`
    """
    def __init__(self, size, points, dilation=0, blur_kernel=0):
        logger.trace("Initializing: %s: (size: %s, points: %s, dilation: %s, blur_kernel: %s)",
                     self.__class__.__name__, size, points, dilation, blur_kernel)
        self._size = size
        self._points = points
        self._dilation = dilation
        self._blur_kernel = blur_kernel
        self._mask = None
        logger.trace("Initialized: %s", self.__class__.__name__)

    def get(self, as_zip=False):
        """ Obtain the mask.

        Parameters
        ----------
        as_zip: bool, optional
            ``True`` if the mask should be returned zipped otherwise ``False``

        Returns
        -------
        :class:`numpy.ndarray` or zipped array
            The mask as a single channel image of the given :attr:`size` dimension. If
            :attr:`as_zip` is ``True`` then the :class:`numpy.ndarray` will be contained within a
            zipped container
        """
        if not np.any(self._mask):
            self._generate_mask()
        retval = compress(self._mask) if as_zip else self._mask
        logger.trace("as_zip: %s, retval type: %s", as_zip, type(retval))
        return retval

    def _generate_mask(self):
        """ Generate the mask.

        Creates the mask applying any requested dilation and blurring and assigns to
        :attr:`_mask`

        Returns
        -------
        :class:`numpy.ndarray`
            The mask as a single channel image of the given :attr:`size` dimension.
        """
        mask = np.zeros((self._size) + (1, ), dtype="float32")
        for landmarks in self._points:
            lms = np.rint(landmarks).astype("int")
            cv2.fillConvexPoly(mask, cv2.convexHull(lms), 1.0, lineType=cv2.LINE_AA)
        if self._dilation != 0:
            mask = cv2.dilate(mask,
                              cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                                        (self._dilation, self._dilation)),
                              iterations=1)
        if self._blur_kernel != 0:
            mask = BlurMask("gaussian", mask, self._blur_kernel).blurred
        logger.trace("mask: (shape: %s, dtype: %s)", mask.shape, mask.dtype)
        self._mask = (mask * 255.0).astype("uint8")


 </s> add  </s> remove         blur_kernel: int, optional
            The kernel size for applying gaussian blur to apply to the mask. `0` for none.
            Default: `0`
        as_zip: bool, optional
            ``True`` if the mask should be returned zipped otherwise ``False``
 </s> add  </s> remove         size: int or tuple
            The size of the aligned mask to retrieve. Should be an `int` if an aligned face is
            being requested, or a ('height', 'width') shape tuple if a full frame is being
            requested
        area: ["mouth", "eyes"]
 </s> add         area: ["face", "mouth", "eye"] </s> remove         aligned: bool, optional
            ``True`` if the returned mask should be for an aligned face. ``False`` if a full frame
            mask should be returned. Default ``True``
        centering: ["legacy", "face", "head"], optional
            Only used if `aligned`=``True``. The centering for the landmarks based mask. Should be
            the same as the centering used for the extracted face that this mask will be applied
            to. "legacy" places the nose in the center of the image (the original method for
            aligning). "face" aligns for the nose to be in the center of the face (top to bottom)
            but the center of the skull for left to right. "head" aligns for the center of the
            skull (in 3D space) being the center of the extracted image, with the crop holding the
            full head. Default: `"face"`
        dilation: int, optional
 </s> add         blur_kernel: int
            The size of the kernel for blurring the mask edges
        dilation: int
        :class:`numpy.ndarray`
            The generated landmarks mask for the selected area
              ``True`` if the mask should be returned zipped otherwise ``False``
  
          Returns
          -------
        :class:`numpy.ndarray`
            The generated landmarks mask for the selected area
        :class:`numpy.ndarray`
            The generated landmarks mask for the selected area
        :class:`numpy.ndarray`
            The generated landmarks mask for the selected area
        :class:`numpy.ndarray`
            The generated landmarks mask for the selected area
          """
          # TODO Face mask generation from landmarks
          logger.trace("size: %s, area: %s, aligned: %s, dilation: %s, blur_kernel: %s, as_zip: %s",
                       size, area, aligned, dilation, blur_kernel, as_zip)
          areas = dict(mouth=[slice(48, 60)], eyes=[slice(36, 42), slice(42, 48)])
keep keep keep keep 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/align/detected_face.py