{
  "id": "tensorflow/graph-mode-placeholder-in-eager",
  "signature": "RuntimeError: tf.placeholder() is not compatible with eager execution. Use tf.keras.Input() instead.",
  "signature_zh": "RuntimeError: tf.placeholder() 与急切执行不兼容。请改用 tf.keras.Input()。",
  "regex": "tf\\.placeholder\\(\\) is not compatible with eager execution",
  "domain": "tensorflow",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "TensorFlow 2.x runs in eager mode by default, but the code uses tf.placeholder which is a graph-mode API removed in TF2.",
  "root_cause_type": "generic",
  "root_cause_zh": "TensorFlow 2.x 默认以急切模式运行，但代码使用了 tf.placeholder，这是 TF2 中已移除的图模式 API。",
  "versions": [
    {
      "version": "2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.3",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Disable eager execution with tf.compat.v1.disable_eager_execution()",
      "why_fails": "Disabling eager execution may cause other TF2 features to break, and is not recommended for new code.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Replace placeholder with tf.Variable",
      "why_fails": "tf.Variable is for model parameters, not for input tensors; it will change the model semantics.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Replace all tf.placeholder calls with tf.keras.Input(shape=..., dtype=...) and rebuild the model using the Keras Functional API.",
      "success_rate": 0.95,
      "how": "Replace all tf.placeholder calls with tf.keras.Input(shape=..., dtype=...) and rebuild the model using the Keras Functional API.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you must use graph mode, wrap the code in a @tf.function decorator and use tf.compat.v1.placeholder inside a tf.compat.v1.Graph() context, but this is not future-proof.",
      "success_rate": 0.7,
      "how": "If you must use graph mode, wrap the code in a @tf.function decorator and use tf.compat.v1.placeholder inside a tf.compat.v1.Graph() context, but this is not future-proof.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Replace all tf.placeholder calls with tf.keras.Input(shape=..., dtype=...) and rebuild the model using the Keras Functional API.",
    "If you must use graph mode, wrap the code in a @tf.function decorator and use tf.compat.v1.placeholder inside a tf.compat.v1.Graph() context, but this is not future-proof."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/eager",
  "official_doc_section": null,
  "error_code": "EPLE",
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-05-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}