{
  "id": "tensorflow/iterator-get-next-failed-precondition",
  "signature": "FailedPreconditionError: GetNext() failed because the iterator has not been initialized",
  "signature_zh": "FailedPreconditionError: GetNext() 失败，因为迭代器尚未初始化",
  "regex": "FailedPreconditionError: GetNext\\(\\) failed because the iterator has not been initialized",
  "domain": "tensorflow",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A tf.data iterator was used without being initialized, typically in TF1 style code or when using tf.compat.v1.data.make_one_shot_iterator incorrectly.",
  "root_cause_type": "generic",
  "root_cause_zh": "tf.data 迭代器在使用前未初始化，常见于 TF1 风格代码或错误使用 tf.compat.v1.data.make_one_shot_iterator。",
  "versions": [
    {
      "version": "tensorflow 2.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The iterator still lacks initialization; only a fresh session restart is attempted.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The initialization must happen before any get_next call, not after.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Initialize the iterator explicitly before fetching: iterator = dataset.make_initializable_iterator(); sess.run(iterator.initializer); then sess.run(get_next).",
      "success_rate": 0.9,
      "how": "Initialize the iterator explicitly before fetching: iterator = dataset.make_initializable_iterator(); sess.run(iterator.initializer); then sess.run(get_next).",
      "condition": "",
      "sources": []
    },
    {
      "action": "Switch to TF2-style eager iteration: for batch in dataset: ... instead of using iterators.",
      "success_rate": 0.95,
      "how": "Switch to TF2-style eager iteration: for batch in dataset: ... instead of using iterators.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Initialize the iterator explicitly before fetching: iterator = dataset.make_initializable_iterator(); sess.run(iterator.initializer); then sess.run(get_next).",
    "Switch to TF2-style eager iteration: for batch in dataset: ... instead of using iterators."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/guide/data#using_the_iterator_api",
  "official_doc_section": null,
  "error_code": "FPRECOND",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "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": []
}