deepfakes/faceswap · error · FaceswapError

Trainer name could not be read from state file.

Error message

Trainer name could not be read from state file.

What it means

Raised when the single *_state.json file was loaded successfully but does not contain a 'name' key (or it maps to an empty/None value). The 'name' entry records the trainer plugin that created the model; without it convert cannot select the model class to load the weights.

Source

Thrown at scripts/convert.py:874

        model_dir
            The folder that contains the trained Faceswap model

        Returns
        -------
        The name of the Faceswap model being used.
        """
        state_files = [fname for fname in os.listdir(str(model_dir))
                       if fname.endswith("_state.json")]
        if len(state_files) != 1:
            raise FaceswapError("There should be 1 state file in your model folder. "
                                f"{len(state_files)} were found.")
        state_file = os.path.join(str(model_dir), state_files[0])

        state = self._serializer.load(state_file)
        trainer = state.get("name", None)

        if not trainer:
            raise FaceswapError("Trainer name could not be read from state file.")
        logger.debug("Trainer from state file: '%s'", trainer)
        return trainer

    def launch(self, load_queue: EventQueue) -> None:
        """Launch the prediction process in a background thread.

        Starts the prediction thread and returns the thread.

        Parameters
        ----------
        load_queue
            The queue that contains images and detected faces for feeding the model
        """
        self._in_queue = load_queue
        self._thread = MultiThread(self._predict_faces, thread_count=1)
        self._thread.start()

    def _predict_faces(self) -> None:

View on GitHub (pinned to f530cb7508)

Solutions

  1. Inspect the state file: `python -c "import json;print(json.load(open('model/_state.json')))` and check whether a 'name' key exists.
  2. If missing, add the correct trainer name (e.g. "original", "dfl-sae", "phaze-a") as the 'name' value, matching the model weights in the folder.
  3. If you do not know the trainer, check the model weights filename prefix or training logs, then restore/fix the state file accordingly.
  4. As a last resort restore the state file from a backup of the training run.

Example fix

# before (state file contents)
{"timestamp": 1690000000, "iterations": 100000}   # no "name" key -> convert fails

# after
{"name": "original", "timestamp": 1690000000, "iterations": 100000}
Defensive patterns

Strategy: validation

Validate before calling

import json

def state_has_trainer(state_file: str) -> bool:
    with open(state_file, encoding="utf-8") as fh:
        state = json.load(fh)
    return bool(state.get("name"))

Try / catch

from lib.exceptions import FaceswapError
try:
    trainer = get_trainer(model_dir)
except FaceswapError as err:
    if "Trainer name" in str(err):
        # inspect and repair the state file
        ...

Prevention

When it happens

Trigger: Calling convert with a model folder whose *_state.json parses as JSON but `state.get("name", None)` returns falsy — either the key is absent, null, or an empty string. Typical with hand-edited state files, state files from a much older/other Faceswap fork, or a corrupted-but-valid-JSON file.

Common situations: Migrating a model from an old Faceswap version or a different fork whose state schema lacked 'name'; manually editing the state JSON and removing/renaming the key; a truncated write during training where serialization still produced valid JSON.

Related errors


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