     ~lib.image.count_frames
     ~lib.image.encode_image
     ~lib.image.generate_thumbnail
     ~lib.image.hex_to_rgb
     ~lib.image.read_image
     ~lib.image.read_image_batch
     ~lib.image.read_image_meta
     ~lib.image.read_image_meta_batch
     ~lib.image.rgb_to_hex
  
 
</s> remove    ~lib.image.read_image_hash
   ~lib.image.read_image_hash_batch
 </s> add    ~lib.image.read_image_meta
   ~lib.image.read_image_meta_batch </s> remove    ~lib.image.encode_image_with_hash
 </s> add    ~lib.image.encode_image </s> remove 
        if no_hash:
            logger.warning("%s image(s) were not found in the alignments file. This will likely "
                           "result in sub-par sorting results, so you should check the output "
                           "carefully", no_hash)

 </s> add  </s> remove         if (any(version == 1.0 for version in alignments.versions.values())
                and self._config["centering"] != "legacy"):
            logger.warning("You are using legacy extracted faces but have selected '%s' "
                           "centering which is incompatible. Switching centering to 'legacy'",
                           self._config["centering"])
            self._config["centering"] = "legacy"
            self._model.config["centering"] = "legacy"
 </s> add         # Update centering if it has been changed by legacy facesets in TrainingAlignments
        self._config["centering"] = self._model.config["centering"] </s> remove     def _get_aligned_faces(self, input_sizes):
        """ Pre-generate aligned faces as they are needed for all training functions.
 </s> add         # Validate image is the same size as the other images for the side
        if width != self._image_sizes[side]:
            msg = ("All training images for each side must be of the same size.\nImages "
                   "in side '{}' have mismatched sizes {} and {}.\nPlease double check "
                   "your dataset".format(side.upper(), self._image_sizes[side], width))
            raise FaceswapError(msg)

    def _update_legacy_facesets(self):
        """ Update the png header data for legacy face sets that do not contain the meta data in
        the exif header.
        """
        if self._validate_metadata(output_warning=False):
            logger.debug("All faces contain valid header information")
            return

        for side, png_meta in self._detected_faces.items():
            if all(png_meta.values()):
                continue
            filenames = [filename for filename, meta in png_meta.items() if not meta]
            logger.info("Legacy faces discovered for side '%s'. Updating %s images...",
                        side.upper(), len(filenames))
            alignments = Alignments(*os.path.split(self._get_alignments_path(side)))
            self._alignments_version.setdefault(side, set()).add(alignments.version)

            executor = futures.ThreadPoolExecutor()
            with executor:
                images = {executor.submit(update_legacy_png_header, filename, alignments): filename
                          for filename in filenames}

                for future in tqdm(
                        futures.as_completed(images),
                        desc="Updating legacy training images ({})".format(side.upper()),
                        total=len(filenames),
                        leave=False):
                    detected_face = DetectedFace()
                    detected_face.from_png_meta(future.result())
                    png_meta[images[future]] = detected_face

    def _get_alignments_path(self, side):
        """ Obtain the path to an alignments file for the given training side.

        Used for updating legacy facesets to contain the meta information within the image header

        Parameters
        ----------
        side: ["a" or "b"]
            The training side to obtain the alignments file for.

        Returns
        -------
        str
            The full path to the training alignments file

        Raises
        ------
        FaceswapError
            If an alignments file cannot be located
        """
        alignments_path = getattr(self._args, "alignments_path_{}".format(side))
        if not alignments_path:
            image_path = getattr(self._args, "input_{}".format(side))
            alignments_path = os.path.join(image_path, "alignments.fsa")
        if not os.path.exists(alignments_path):
            msg = ("You are using a legacy faceset that does not contain embedded "
                   "meta-information. An alignments file must be provided so that these files can "
                   "be updated.\n"
                   f"Alignments file does not exist: '{alignments_path}'")
            raise FaceswapError(msg)
        return alignments_path

    # <<< VALIDATE LOADED DETECTED FACE INFORMATION >>>
    def _validity_check(self):
        """ Check the validity of the finally loaded data.

        Ensure that each side has consistent alignments versions.
        Ensure that each side has a full compliment of metadata.
        """
        invalid = [side.upper()
                   for side, version in self._alignments_version.items() if len(version) > 1]
        if invalid:
            raise FaceswapError("Mixing legacy and full head extracted facesets is not supported. "
                                "The following side(s) contain a mix of extracted face "
                                "types: {}".format(invalid))
        # Replace check alignments version sets with actual floats
        self._alignments_version = {key: val.pop()
                                    for key, val in self._alignments_version.items()}

        if 1.0 in self._alignments_version.values() and self._config["centering"] != "legacy":
            logger.warning("You are using legacy extracted faces but have selected '%s' "
                           "centering which is incompatible. Switching centering to 'legacy'",
                           self._config["centering"])
            self._config["centering"] = "legacy"

        self._validate_metadata(output_warning=True)
        self._validate_masks()

    def _validate_metadata(self, output_warning=True):
        """ Validate that all images to be trained on have associated alignments data. If not
        generate a warning.
   ~lib.image.png_read_meta
   ~lib.image.png_write_meta
     ~lib.image.count_frames
     ~lib.image.encode_image
     ~lib.image.generate_thumbnail
     ~lib.image.hex_to_rgb
   ~lib.image.png_read_meta
   ~lib.image.png_write_meta
     ~lib.image.read_image
     ~lib.image.read_image_batch
     ~lib.image.read_image_meta
     ~lib.image.read_image_meta_batch
     ~lib.image.rgb_to_hex
  
keep keep keep add keep keep keep keep keep keep
 Update extracted faces to use PNG EXIF data (#1123)

Documentation
  - Update Usage.md, align.rst and image.rst
lib.image.py
  - read_image - Remove hash return, add metadata return
  - Remove read_image_hash functions
  - Add read_image_meta functios
  - Replace encode_image_with_hash with encode_image (to store metadata)
  - Add png meta reading and writing functions
  - Update Image Loaders/Savers to handle metadata rather than hashes
lib.training_data
  - Naming updates to remove references to hashes
lib.align.Alignments
  - Add versioning notes
  - Increment alignments version to 2.1
  - Deprecate hashing lookup functions
  - Replace filter_hashes with filter_faces
lib.align.detected_face
  - DetectedFace
    - Remove hash property
    - Add png header data serializing/deserializing functions
  - Mask
    - Add png header data serializing/deserializing functions
  - add update_legacy_png_header function to update png meta data
lib.cli.args - Deprecate alignments files for training
- plugins.train.trainer
  - Update alignments/mask code to read png header data
- scripts.convert
  - Aligned images folder - read data from png headers
- scripts.extract
  - Write png header information and no longer store hash of face
- tools.alignments
  - remove leftover-faces, merge and update-hashes jobs
  - Update jobs to use png meta data rather than hashes
- tools.manual
  - Update extract code to output png meta data and don't store hashes
  - Perform check on launch that tool is not pointing at a faces folder
tools.mask
  - Update to use png meta data
tools.sort
  - Update to use png meta data 
docs/full/lib/image.rst