{"record":{"id":"5bc7b2e771bd293f","repo":"deepfakes/faceswap","slug":"error-loading-weights-file-self-weights-file","errorCode":null,"errorMessage":"Error loading weights file {self._weights_file}.","messagePattern":"Error loading weights file (.+?)\\.","errorType":"exception","errorClass":"FaceswapError","httpStatus":null,"severity":"error","filePath":"plugins/train/model/_base/io.py","lineNumber":519,"sourceCode":"\n    def _get_weights_model(self) -> list[k_models.Model]:\n        \"\"\"Obtain a list of all sub-models contained within the weights model.\n\n        Returns\n        -------\n        List of all models contained within the .keras file\n\n        Raises\n        ------\n        FaceswapError\n            In the event of a failure to load the weights, or the weights belonging to a different\n            model\n        \"\"\"\n        retval = get_all_sub_models(k_models.load_model(    # pyright:ignore[reportArgumentType]\n            self._weights_file,\n            compile=False))\n        if not retval:\n            raise FaceswapError(f\"Error loading weights file {self._weights_file}.\")\n\n        if retval[0].name != self._name:\n            raise FaceswapError(f\"You are attempting to load weights from a '{retval[0].name}' \"\n                                f\"model into a '{self._name}' model. This is not supported.\")\n        return retval\n\n    def _load_layer_weights(self,\n                            layer: layers.Layer,\n                            sub_weights: layers.Layer,\n                            model_name: str) -> T.Literal[-1, 0, 1]:\n        \"\"\"Load the weights for a single layer.\n\n        Parameters\n        ----------\n        layer\n            The layer to set the weights for\n        sub_weights\n            The list of layers in the weights model to load weights from","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/plugins/train/model/_base/io.py#L501-L537","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a weights file produced by a Faceswap training session for the same model plugin.","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.","Remove the load-weights option if you actually want a fresh training run."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import keras.models as km\nfrom lib.model.session import get_all_sub_models  # or the model's helper\nsubs = get_all_sub_models(km.load_model(weights_file, compile=False))\nassert subs, \"weights file exposes no sub-models; it is not a Faceswap weights file\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use weights files exported from Faceswap training sessions.","Keep a note of which plugin/session each weights file came from to avoid mix-ups."],"tags":["faceswap","weights","keras","transfer-learning"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}