deepfakes/faceswap · error · FaceswapError

The state file '{state_file}' does not exist. This model can

Error message

The state file '{state_file}' does not exist. This model cannot be ported

What it means

FaceswapError raised when porting a legacy Faceswap 2 model to Faceswap 3: the code derives a companion state file path (<model>_state.json next to the .h5) and that file does not exist. The state file holds the training configuration needed to rebuild the model architecture, so without it the port cannot proceed. Only the .h5 was found; the JSON sidecar is missing.

Source

Thrown at plugins/train/model/_base/update.py:109

            item[2] = int(item[2])
        logger.debug("Unwrapped outputs: %s to: %s", outputs, retval)
        return retval

    def _get_clip_config(self) -> dict[str, T.Any]:
        """Build a clip model from the configuration information stored in the legacy state file

        Returns
        -------
        The new keras configuration for a Clip model

        Raises
        ------
        FaceswapError
            If the clip model cannot be built
        """
        state_file = f"{os.path.splitext(self._old_model_file)[0]}_state.json"
        if not os.path.isfile(state_file):
            raise FaceswapError(
                f"The state file '{state_file}' does not exist. This model cannot be ported")

        with open(state_file, "r", encoding="utf-8") as ifile:
            config = json.load(ifile)

        logger.debug("Loaded legacy config '%s': %s", state_file, config)
        net_name = config.get("config", {}).get("enc_architecture", "")
        scaling = config.get("config", {}).get("enc_scaling", 0) / 100

        # Import here to prevent circular imports
        from plugins.train.model.phaze_a import _MODEL_MAPPING  # pylint:disable=C0415
        vit_info = _MODEL_MAPPING.get(net_name)

        if not scaling or not vit_info:
            raise FaceswapError(
                f"Clip network could not be found in '{state_file}'. Discovered network is "
                f"'{net_name}' with encoder scaling: {scaling}. This model cannot be ported")

View on GitHub (pinned to f530cb7508)

Solutions

  1. Restore the matching <model>_state.json into the same folder as the .h5 file
  2. If the .h5 was renamed, rename the state JSON to share the same basename
  3. If the state file is lost, the model cannot be ported; retrain or obtain the full original model folder

Example fix

# before
/models/model.h5            # present
/models/model_state.json     # missing -> error

# after (shell)
cp /backup/model_state.json /models/
# basename of h5 and state json must match before the _state.json suffix
Defensive patterns

Strategy: validation

Validate before calling

import os
state = f"{os.path.splitext(model_h5)[0]}_state.json"
if not os.path.isfile(state):
    raise SystemExit(f"Missing {state}; porting requires the .h5 and its state json together")

Prevention

When it happens

Trigger: Porting with an .h5 file whose sibling <basename>_state.json was deleted or never copied. os.path.isfile on f'{splitext(old_model_file)[0]}_state.json' returns False.

Common situations: User copies only the .h5 weights file out of a model folder, loses the state file in a partial backup, or renames the .h5 without renaming the state JSON.

Related errors


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