{"record":{"id":"9510b7cc5efba38b","repo":"keras-team/keras","slug":"shape-mismatch-in-name-for-weight-symbolic-weigh","errorCode":null,"errorMessage":"Shape mismatch in {name}for weight {symbolic_weights[i].path}. Weight expects shape {expected_shape}. Received saved weight with shape {received_shape}","messagePattern":"Shape mismatch in (.+?)for weight (.+?)\\. Weight expects shape (.+?)\\. Received saved weight with shape (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/saving/legacy_h5_format.py","lineNumber":460,"sourceCode":"        ValueError: in case of mismatch between provided\n            model/layer and weights.\n    \"\"\"\n    for i, weight_value in enumerate(weight_values):\n        expected_shape = symbolic_weights[i].shape\n        received_shape = weight_value.shape\n        if expected_shape != received_shape:\n            if skip_mismatch:\n                warnings.warn(\n                    f\"Skipping loading weights for {name}\"\n                    f\"due to mismatch in shape for \"\n                    f\"weight {symbolic_weights[i].path}. \"\n                    f\"Weight expects shape {expected_shape}. \"\n                    \"Received saved weight \"\n                    f\"with shape {received_shape}\",\n                    stacklevel=2,\n                )\n                continue\n            raise ValueError(\n                f\"Shape mismatch in {name}\"\n                f\"for weight {symbolic_weights[i].path}. \"\n                f\"Weight expects shape {expected_shape}. \"\n                \"Received saved weight \"\n                f\"with shape {received_shape}\"\n            )\n        symbolic_weights[i].assign(weight_value)\n\n    if hasattr(instance, \"finalize_state\") and symbolic_weights:\n        instance.finalize_state()\n\n\ndef load_weights_from_hdf5_group_by_name(group, model, skip_mismatch=False):\n    \"\"\"Implements name-based weight loading (instead of topological loading).\n\n    Layers that have no matching name are skipped.\n\n    Args:","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/saving/legacy_h5_format.py#L442-L478","documentation":"Error \"Shape mismatch in {name}for weight {symbolic_weights[i].path}. Weight expects shape {expected_shape}. Received saved weight with shape {received_shape}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/legacy/saving/legacy_h5_format.py:460 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}