Пример #1
0
    def _predict(self, batch):
        """ Wrap models predict function in rotations """
        batch["rotmat"] = [np.array([]) for _ in range(len(batch["feed"]))]
        found_faces = [np.array([]) for _ in range(len(batch["feed"]))]
        for angle in self.rotation:
            # Rotate the batch and insert placeholders for already found faces
            self._rotate_batch(batch, angle)
            batch = self.predict(batch)

            if angle != 0 and any([face.any()
                                   for face in batch["prediction"]]):
                logger.verbose("found face(s) by rotating image %s degrees",
                               angle)

            found_faces = [
                face if not found.any() else found
                for face, found in zip(batch["prediction"], found_faces)
            ]

            if all([face.any() for face in found_faces]):
                logger.trace("Faces found for all images")
                break

        batch["prediction"] = found_faces
        logger.trace(
            "detect_prediction output: (filenames: %s, prediction: %s, rotmat: %s)",
            batch["filename"], batch["prediction"], batch["rotmat"])
        return batch
Пример #2
0
    def _predict(self, batch):
        """ Wrap models predict function in rotations """
        batch["rotmat"] = [np.array([]) for _ in range(len(batch["feed"]))]
        found_faces = [np.array([]) for _ in range(len(batch["feed"]))]
        for angle in self.rotation:
            # Rotate the batch and insert placeholders for already found faces
            self._rotate_batch(batch, angle)
            try:
                batch = self.predict(batch)
            except tf_errors.ResourceExhaustedError as err:
                msg = (
                    "You do not have enough GPU memory available to run detection at the "
                    "selected batch size. You can try a number of things:"
                    "\n1) Close any other application that is using your GPU (web browsers are "
                    "particularly bad for this)."
                    "\n2) Lower the batchsize (the amount of images fed into the model) by "
                    "editing the plugin settings (GUI: Settings > Configure extract settings, "
                    "CLI: Edit the file faceswap/config/extract.ini)."
                    "\n3) Enable 'Single Process' mode.")
                raise FaceswapError(msg) from err
            except Exception as err:
                if get_backend() == "amd":
                    # pylint:disable=import-outside-toplevel
                    from lib.plaidml_utils import is_plaidml_error
                    if (is_plaidml_error(err)
                            and ("CL_MEM_OBJECT_ALLOCATION_FAILURE"
                                 in str(err).upper()
                                 or "enough memory for the current schedule"
                                 in str(err).lower())):
                        msg = (
                            "You do not have enough GPU memory available to run detection at "
                            "the selected batch size. You can try a number of things:"
                            "\n1) Close any other application that is using your GPU (web "
                            "browsers are particularly bad for this)."
                            "\n2) Lower the batchsize (the amount of images fed into the "
                            "model) by editing the plugin settings (GUI: Settings > Configure "
                            "extract settings, CLI: Edit the file "
                            "faceswap/config/extract.ini).")
                        raise FaceswapError(msg) from err
                raise

            if angle != 0 and any([face.any()
                                   for face in batch["prediction"]]):
                logger.verbose("found face(s) by rotating image %s degrees",
                               angle)

            found_faces = [
                face if not found.any() else found
                for face, found in zip(batch["prediction"], found_faces)
            ]

            if all([face.any() for face in found_faces]):
                logger.trace("Faces found for all images")
                break

        batch["prediction"] = found_faces
        logger.trace(
            "detect_prediction output: (filenames: %s, prediction: %s, rotmat: %s)",
            batch["filename"], batch["prediction"], batch["rotmat"])
        return batch