{"record":{"id":"6c6d8394621cf65c","repo":"deepfakes/faceswap","slug":"there-should-be-1-state-file-in-your-model-folder","errorCode":null,"errorMessage":"There should be 1 state file in your model folder. {len(state_files)} were found.","messagePattern":"There should be 1 state file in your model folder\\. (.+?) were found\\.","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"scripts/convert.py","lineNumber":866,"sourceCode":"\n    def _get_model_name(self, model_dir: str) -> str:\n        \"\"\"Return the name of the Faceswap model used.\n\n        Retrieve the name of the model from the model's state file.\n\n        Parameters\n        ----------\n        model_dir\n            The folder that contains the trained Faceswap model\n\n        Returns\n        -------\n        The name of the Faceswap model being used.\n        \"\"\"\n        state_files = [fname for fname in os.listdir(str(model_dir))\n                       if fname.endswith(\"_state.json\")]\n        if len(state_files) != 1:\n            raise FaceswapError(\"There should be 1 state file in your model folder. \"\n                                f\"{len(state_files)} were found.\")\n        state_file = os.path.join(str(model_dir), state_files[0])\n\n        state = self._serializer.load(state_file)\n        trainer = state.get(\"name\", None)\n\n        if not trainer:\n            raise FaceswapError(\"Trainer name could not be read from state file.\")\n        logger.debug(\"Trainer from state file: '%s'\", trainer)\n        return trainer\n\n    def launch(self, load_queue: EventQueue) -> None:\n        \"\"\"Launch the prediction process in a background thread.\n\n        Starts the prediction thread and returns the thread.\n\n        Parameters\n        ----------","sourceCodeStart":848,"sourceCodeEnd":884,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/scripts/convert.py#L848-L884","documentation":"Raised by the convert process when the model folder does not contain exactly one '<name>_state.json' file. The state file stores which trainer (model plugin, e.g. 'original' or 'dfl-sae') produced the model, and convert needs this single file to load the correct model architecture. Zero state files means you pointed convert at a folder that was never trained in; two or more means multiple models' state files coexist in one folder.","triggerScenarios":"Calling `python scripts/convert.py -m <model_dir>` where os.listdir(model_dir) returns either 0 or >= 2 filenames ending in '_state.json'. Happens when the model dir is empty/wrong, when a second model was trained into the same folder, or when a state file was manually copied in.","commonSituations":"Typos in the --model-dir argument; re-using a training folder for a different model architecture without cleaning it; copying model files between machines and accidentally duplicating state files; pointing at the parent folder instead of the actual model subfolder.","solutions":["Run convert with the exact folder that was used for training: `python scripts/convert.py -m /path/to/model` and verify with `ls /path/to/model/*_state.json` that exactly one file exists.","If two or more *_state.json files exist, move the stale one(s) (from previous experiments) out of the folder, keeping only the state file matching the model .h5/.keras weights you want to convert with.","If zero state files exist, the folder is not a trained Faceswap model folder — retrain into it or point --model-dir at the real training output folder.","If the state file was lost (e.g. partial copy), retrain briefly or restore it from a backup; convert cannot infer the trainer without it."],"exampleFix":"# before\npython scripts/convert.py -i in/ -o out/ -a aligned/ -m ~/faceswap/models   # folder holds 2 state files\n\n# after\nls ~/faceswap/models/*_state.json\n# move stale one out:\nmv ~/faceswap/models/original_state.json ~/backup/\npython scripts/convert.py -i in/ -o out/ -a aligned/ -m ~/faceswap/models","handlingStrategy":"validation","validationCode":"import os, glob\n\ndef validate_model_dir(model_dir: str) -> str:\n    state_files = [f for f in os.listdir(model_dir) if f.endswith(\"_state.json\")]\n    if len(state_files) != 1:\n        raise SystemExit(\n            f\"Expected exactly 1 *_state.json in {model_dir}, found {len(state_files)}: {state_files}\")\n    return os.path.join(model_dir, state_files[0])","typeGuard":null,"tryCatchPattern":"from lib.exceptions import FaceswapError\ntry:\n    trainer = get_trainer(model_dir)\nexcept FaceswapError as err:\n    print(f\"Model folder invalid: {err}\")\n    # list candidates to help the user pick\n    print([f for f in os.listdir(model_dir) if f.endswith(\"_state.json\")])\n    raise SystemExit(1)","preventionTips":["One dedicated folder per trained model; never train a second model into the same folder.","Script a preflight check that globs *_state.json and asserts exactly one match before launching convert.","Keep backups of the model folder including the state file alongside the weights."],"tags":["faceswap","convert","model-state","filesystem","configuration"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}