{
  "id": "tensorflow/placeholder-not-supported-eager",
  "signature": "RuntimeError: tf.placeholder() is not compatible with eager execution.",
  "signature_zh": "RuntimeError：tf.placeholder() 与即时执行不兼容。",
  "regex": "tf\\.placeholder\\(\\) is not compatible with eager execution",
  "domain": "tensorflow",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Using tf.placeholder in TensorFlow 2.x where eager execution is enabled by default; placeholders are only for graph mode.",
  "root_cause_type": "generic",
  "root_cause_zh": "在默认启用即时执行的 TensorFlow 2.x 中使用 tf.placeholder；占位符仅适用于图模式。",
  "versions": [
    {
      "version": "tensorflow 2.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.16",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disabling eager execution with `tf.compat.v1.disable_eager_execution()` works but loses TF2 benefits and is deprecated.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Replacing placeholder with `tf.Variable` fails because variables hold specific values, not input slots.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Replace `tf.placeholder(tf.float32, shape=[None, 10])` with function arguments in eager mode. For example: `def model_fn(x): return tf.keras.layers.Dense(10)(x)`. Then call `model_fn(input_tensor)` directly.",
      "success_rate": 0.95,
      "how": "Replace `tf.placeholder(tf.float32, shape=[None, 10])` with function arguments in eager mode. For example: `def model_fn(x): return tf.keras.layers.Dense(10)(x)`. Then call `model_fn(input_tensor)` directly.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If graph mode is required, use `tf.function` with input signatures: `@tf.function(input_signature=[tf.TensorSpec(shape=[None, 10], dtype=tf.float32)])`.",
      "success_rate": 0.9,
      "how": "If graph mode is required, use `tf.function` with input signatures: `@tf.function(input_signature=[tf.TensorSpec(shape=[None, 10], dtype=tf.float32)])`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Replace `tf.placeholder(tf.float32, shape=[None, 10])` with function arguments in eager mode. For example: `def model_fn(x): return tf.keras.layers.Dense(10)(x)`. Then call `model_fn(input_tensor)` directly.",
    "If graph mode is required, use `tf.function` with input signatures: `@tf.function(input_signature=[tf.TensorSpec(shape=[None, 10], dtype=tf.float32)])`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/eager",
  "official_doc_section": null,
  "error_code": "PLH",
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-10-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}