{
  "id": "tensorflow/keras-functional-api-merging-bug",
  "signature": "ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor(type_spec=TensorSpec(shape=(None, 64), dtype=tf.float32, name='input_2')) at layer 'dense_2'",
  "signature_zh": "ValueError: 图断开连接：无法在层 'dense_2' 处获取张量 KerasTensor(type_spec=TensorSpec(shape=(None, 64), dtype=tf.float32, name='input_2')) 的值",
  "regex": "ValueError: Graph disconnected: cannot obtain value for tensor KerasTensor\\(type_spec=.*\\) at layer '.*'",
  "domain": "tensorflow",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A Keras Functional API model has a disconnected graph because an intermediate tensor was not passed as input to a downstream layer, often due to incorrect merging of two sub-models or missing skip connection.",
  "root_cause_type": "generic",
  "root_cause_zh": "Keras 函数式 API 模型的图断开连接，因为中间张量未作为输入传递给下游层，通常是由于两个子模型合并不正确或缺少跳跃连接。",
  "versions": [
    {
      "version": "tensorflow 2.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The error is topological; adding layers does not automatically connect the missing tensor.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Sequential API does not support branching or merging, which is often the intended architecture.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Trace the model definition and ensure every intermediate tensor used in a layer call is passed as an argument. For example, if merging two branches: merged = layers.concatenate([branch1_output, branch2_output]) then pass merged to the next layer. Check that all KerasTensors are connected in the functional graph.",
      "success_rate": 0.95,
      "how": "Trace the model definition and ensure every intermediate tensor used in a layer call is passed as an argument. For example, if merging two branches: merged = layers.concatenate([branch1_output, branch2_output]) then pass merged to the next layer. Check that all KerasTensors are connected in the functional graph.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use model.summary() and plot_model(model, show_shapes=True) to visualize the graph and identify the disconnected tensor, then correct the layer call that should use that tensor.",
      "success_rate": 0.9,
      "how": "Use model.summary() and plot_model(model, show_shapes=True) to visualize the graph and identify the disconnected tensor, then correct the layer call that should use that tensor.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "跟踪模型定义，确保在层调用中使用的每个中间张量都作为参数传递。例如，合并两个分支：merged = layers.concatenate([branch1_output, branch2_output])，然后将 merged 传递给下一层。检查所有 KerasTensor 在函数图中是否已连接。",
    "使用 model.summary() 和 plot_model(model, show_shapes=True) 可视化图并识别断开的张量，然后修正应使用该张量的层调用。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/keras/functional_api#graph_of_layers",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.89,
  "fix_success_rate": 0.93,
  "resolvable": "true",
  "first_seen": "2023-02-14",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}