deepfakes/faceswap · error · FaceswapError

The images to be sorted do not contain alignment data. Image

Error message

The images to be sorted do not contain alignment data. Images must have been generated by Faceswap's Extract process.\nIf you are sorting an older face set, then you should re-extract the faces from your source alignments file to generate this data.

What it means

Sort tool aligned-metric path (sort_methods_aligned.py, base for sort-by-yaw/pitch/roll/size/distance etc.): the per-image alignments metadata passed in is falsy, so there is no landmarks_xy to build an AlignedFace from. All aligned-metric sorts share this guard and fail identically.

Source

Thrown at tools/sort/sort_methods_aligned.py:88

        ----------
        filename: str
            The filename of the currently processing image
        image: :class:`np.ndarray` or ``None``
            A face image loaded from disk or ``None``
        alignments: dict or ``None``
            The alignments dictionary for the aligned face or ``None``
        """
        if self._log_once:
            msg = "Grouping" if self._is_group else "Sorting"
            logger.info("%s by %s...", msg, self._method)
            self._log_once = False

        if not alignments:
            msg = ("The images to be sorted do not contain alignment data. Images must have "
                   "been generated by Faceswap's Extract process.\nIf you are sorting an "
                   "older face set, then you should re-extract the faces from your source "
                   "alignments file to generate this data.")
            raise FaceswapError(msg)

        face = AlignedFace(alignments.landmarks_xy)
        if (not self._logged_lm_count_once
                and face.landmark_type == LandmarkType.LM_2D_4
                and self.__class__.__name__ != "SortSize"):
            logger.warning("You have selected to sort by an aligned metric, but at least one face "
                           "does not contain facial landmark data. This probably won't work")
            self._logged_lm_count_once = True
        self._result.append((filename, self._get_metric(face)))


class SortDistance(SortAlignedMetric):
    """ Sorting mechanism for sorting faces from small to large """
    def _get_metric(self, aligned_face: AlignedFace) -> float:
        """ Obtain the distance from mean face metric for the given face

        Parameters
        ----------

View on GitHub (pinned to f530cb7508)

Solutions

  1. Re-extract faces with Faceswap's extract so each PNG embeds alignment data, then sort.
  2. Purge non-Faceswap PNGs from the input folder.
  3. Fall back to a histogram/pixel-based sort method that does not require alignment data if re-extraction is not possible.

Example fix

# before
python tools.py sort -t yaw -i faces/
# FaceswapError: ... do not contain alignment data ...

# after
python scripts/extract.py -i frames/ -o faces_fresh/
python tools.py sort -t yaw -i faces_fresh/
Defensive patterns

Strategy: validation

Validate before calling

import os
from lib.image import read_image_meta

def folder_has_alignment_data(folder: str) -> bool:
    pngs = [f for f in os.listdir(folder) if f.lower().endswith(".png")]
    if not pngs:
        return False
    meta = read_image_meta(os.path.join(folder, pngs[0]))
    return meta.get("itxt", {}).get("alignments") is not None

Try / catch

from lib.exceptions import FaceswapError
try:
    sorter.sort()
except FaceswapError as err:
    if "alignment data" in str(err):
        raise SystemExit("Re-extract faces with Faceswap before aligned-metric sort") from err
    raise

Prevention

When it happens

Trigger: Running `python tools.py sort -t <yaw|pitch|roll|size|distance|...>` over a folder where one or more PNGs lack Faceswap alignment metadata — same root cause as the identity-sort variant: not extracted by Faceswap, re-saved by a metadata-stripping tool, or from an old extraction.

Common situations: Sorting legacy face sets predating metadata embedding; images passed through compression/editing; mixing manually cropped faces into an extracted folder.

Related errors


AI-assisted analysis of deepfakes/faceswap@f530cb7508 (2026-08-15). Data as JSON: /api/errors/5a230f9a378dd72c. Report an issue: GitHub.