Esempio n. 1
0
 def _validate_non_faces(cls, frames_folder):
     """ Quick check on the input to make sure that a folder of extracted faces is not being
     passed in. """
     if not os.path.isdir(frames_folder):
         logger.debug("Input '%s' is not a folder", frames_folder)
         return
     test_file = next((fname for fname in os.listdir(frames_folder)
                       if os.path.splitext(fname)[-1].lower() == ".png"),
                      None)
     if not test_file:
         logger.debug("Input '%s' does not contain any .pngs",
                      frames_folder)
         return
     test_file = os.path.join(frames_folder, test_file)
     meta = read_image_meta(test_file)
     logger.debug("Test file: (filename: %s, metadata: %s)", test_file,
                  meta)
     if "itxt" in meta and "alignments" in meta["itxt"]:
         logger.error("The input folder '%s' contains extracted faces.",
                      frames_folder)
         logger.error(
             "The Manual Tool works with source frames or a video file, not extracted "
             "faces. Please update your input.")
         sys.exit(1)
     logger.debug(
         "Test input file '%s' does not contain Faceswap header data",
         test_file)
Esempio n. 2
0
    def _get_images(self):
        """ Check the image folders exist and contains valid extracted faces. Obtain image paths.

        Returns
        -------
        dict
            The image paths for each side. The key is the side, the value is the list of paths
            for that side.
        """
        logger.debug("Getting image paths")
        images = dict()
        for side in ("a", "b"):
            image_dir = getattr(self._args, "input_{}".format(side))
            if not os.path.isdir(image_dir):
                logger.error("Error: '%s' does not exist", image_dir)
                sys.exit(1)

            images[side] = get_image_paths(image_dir, ".png")
            if not images[side]:
                logger.error("Error: '%s' contains no images", image_dir)
                sys.exit(1)
            # Validate the first image is a detected face
            test_image = next(img for img in images[side])
            meta = read_image_meta(test_image)
            logger.debug("Test file: (filename: %s, metadata: %s)", test_image,
                         meta)
            if "itxt" not in meta or "alignments" not in meta["itxt"]:
                logger.error(
                    "The input folder '%s' contains images that are not extracted faces.",
                    image_dir)
                logger.error(
                    "You can only train a model on faces generated from Faceswap's "
                    "extract process. Please check your sources and try again."
                )
                sys.exit(1)

            logger.info("Model %s Directory: '%s' (%s images)", side.upper(),
                        image_dir, len(images[side]))
        logger.debug("Got image paths: %s", [(key, str(len(val)) + " images")
                                             for key, val in images.items()])
        self._validate_image_counts(images)
        return images