deepfakes/faceswap · error · FaceswapError

Error loading weights file {self._weights_file}.

Error message

Error loading weights file {self._weights_file}.

What it means

Raised in _get_weights_model when the .keras weights file loads without error but get_all_sub_models returns an empty list — i.e. the file contains no retrievable sub-models, so there is nothing to transfer weights from. It indicates the file is structurally not what Faceswap expects (not a Faceswap-style multi-submodel save).

Source

Thrown at plugins/train/model/_base/io.py:519

    def _get_weights_model(self) -> list[k_models.Model]:
        """Obtain a list of all sub-models contained within the weights model.

        Returns
        -------
        List of all models contained within the .keras file

        Raises
        ------
        FaceswapError
            In the event of a failure to load the weights, or the weights belonging to a different
            model
        """
        retval = get_all_sub_models(k_models.load_model(    # pyright:ignore[reportArgumentType]
            self._weights_file,
            compile=False))
        if not retval:
            raise FaceswapError(f"Error loading weights file {self._weights_file}.")

        if retval[0].name != self._name:
            raise FaceswapError(f"You are attempting to load weights from a '{retval[0].name}' "
                                f"model into a '{self._name}' model. This is not supported.")
        return retval

    def _load_layer_weights(self,
                            layer: layers.Layer,
                            sub_weights: layers.Layer,
                            model_name: str) -> T.Literal[-1, 0, 1]:
        """Load the weights for a single layer.

        Parameters
        ----------
        layer
            The layer to set the weights for
        sub_weights
            The list of layers in the weights model to load weights from

View on GitHub (pinned to f530cb7508)

Solutions

  1. Use a weights file produced by a Faceswap training session for the same model plugin.
  2. Re-check the file: open it in Python (keras.models.load_model) and inspect it — if it is not the expected Faceswap model, obtain the correct file.
  3. Remove the load-weights option if you actually want a fresh training run.
Defensive patterns

Strategy: validation

Validate before calling

import keras.models as km
from lib.model.session import get_all_sub_models  # or the model's helper
subs = get_all_sub_models(km.load_model(weights_file, compile=False))
assert subs, "weights file exposes no sub-models; it is not a Faceswap weights file"

Prevention

When it happens

Trigger: Passing an externally-trained or single-model .keras file (or a corrupt/empty-but-loadable archive) as the load-weights input; k_models.load_model succeeds but yields a model whose traversal produces no sub-models.

Common situations: Trying to warm-start from weights exported from Keras/TF directly rather than from a Faceswap training session; truncated files that still parse; passing a non-weights .keras artifact.

Related errors


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