{
  "id": "tensorflow/keras-model-save-h5-weights",
  "signature": "NotImplementedError: Saving the model to HDF5 format is not supported when the model has multiple outputs with different loss functions",
  "signature_zh": "NotImplementedError：当模型有多个输出且使用不同损失函数时，不支持将模型保存为HDF5格式",
  "regex": "NotImplementedError: Saving the model to HDF5 format is not supported when the model has multiple outputs with different loss functions",
  "domain": "tensorflow",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Keras HDF5 serialization does not support models with heterogeneous loss functions across multiple outputs; the format cannot correctly store the loss configuration.",
  "root_cause_type": "generic",
  "root_cause_zh": "Keras的HDF5序列化不支持在多个输出上使用不同损失函数的模型；该格式无法正确存储损失配置。",
  "versions": [
    {
      "version": "tensorflow>=2.11.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "keras>=2.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "python>=3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Manually editing the HDF5 file to add loss entries.",
      "why_fails": "HDF5 files are binary and not meant for manual editing; the internal structure is complex and likely to break the model loading.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting all loss functions to the same value temporarily to save, then restoring them.",
      "why_fails": "Even if the save succeeds, the model's loss configuration is lost; loading the model will have incorrect loss functions.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Save the model using the SavedModel format instead: `model.save('my_model', save_format='tf')` (or `model.export('my_model')` in TF2.x). This format supports multiple outputs and heterogeneous losses.",
      "success_rate": 0.95,
      "how": "Save the model using the SavedModel format instead: `model.save('my_model', save_format='tf')` (or `model.export('my_model')` in TF2.x). This format supports multiple outputs and heterogeneous losses.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Save only the model weights using `model.save_weights('model_weights.h5')` and then recreate the model architecture with the same loss configuration in code, then load the weights.",
      "success_rate": 0.85,
      "how": "Save only the model weights using `model.save_weights('model_weights.h5')` and then recreate the model architecture with the same loss configuration in code, then load the weights.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Save the model using the SavedModel format instead: `model.save('my_model', save_format='tf')` (or `model.export('my_model')` in TF2.x). This format supports multiple outputs and heterogeneous losses.",
    "Save only the model weights using `model.save_weights('model_weights.h5')` and then recreate the model architecture with the same loss configuration in code, then load the weights."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/keras/serialization_and_saving",
  "official_doc_section": null,
  "error_code": "KHS",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-07-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}