{
  "id": "tensorflow/tflite-quantization-range",
  "signature": "ValueError: Quantization range (min, max) not supported for op 'CONV_2D' with input type float32 and output type uint8",
  "signature_zh": "ValueError：操作'CONV_2D'的量化范围（最小值、最大值）不支持输入类型float32和输出类型uint8",
  "regex": "ValueError: Quantization range \\(min, max\\) not supported for op 'CONV_2D' with input type float32 and output type uint8",
  "domain": "tensorflow",
  "category": "build_error",
  "subcategory": null,
  "root_cause": "During TFLite conversion, the quantization parameters (min/max) for a CONV_2D op are either missing or out of the valid range for uint8 quantization, typically because calibration data did not cover the full activation range.",
  "root_cause_type": "generic",
  "root_cause_zh": "在TFLite转换过程中，CONV_2D操作的量化参数（最小值/最大值）缺失或超出uint8量化的有效范围，通常是因为校准数据未覆盖完整的激活范围。",
  "versions": [
    {
      "version": "tensorflow>=2.12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tflite>=2.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "python>=3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing the number of calibration steps arbitrarily without verifying data diversity.",
      "why_fails": "More steps of the same data does not improve range coverage; the error persists if the calibration set lacks extreme values.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Manually setting min/max to [-128, 127] in the converter options.",
      "why_fails": "TFLite converter ignores manual override for per-op ranges; it expects calibration to provide them.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the calibration dataset includes diverse inputs that trigger both minimum and maximum activation values for the CONV_2D layer. For example, use a balanced subset of training data: representative_dataset = lambda: [tf.random.normal([1, 224, 224, 3]) for _ in range(100)] (but with real data).",
      "success_rate": 0.8,
      "how": "Ensure the calibration dataset includes diverse inputs that trigger both minimum and maximum activation values for the CONV_2D layer. For example, use a balanced subset of training data: representative_dataset = lambda: [tf.random.normal([1, 224, 224, 3]) for _ in range(100)] (but with real data).",
      "condition": "",
      "sources": []
    },
    {
      "action": "Switch to per-channel quantization or use tf.lite.TFLiteConverter with optimizations=[tf.lite.Optimize.DEFAULT] and specify supported_ops=[tf.lite.OpsSet.TFLITE_BUILTINS_INT8] after ensuring full integer quantization is possible.",
      "success_rate": 0.75,
      "how": "Switch to per-channel quantization or use tf.lite.TFLiteConverter with optimizations=[tf.lite.Optimize.DEFAULT] and specify supported_ops=[tf.lite.OpsSet.TFLITE_BUILTINS_INT8] after ensuring full integer quantization is possible.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure the calibration dataset includes diverse inputs that trigger both minimum and maximum activation values for the CONV_2D layer. For example, use a balanced subset of training data: representative_dataset = lambda: [tf.random.normal([1, 224, 224, 3]) for _ in range(100)] (but with real data).",
    "Switch to per-channel quantization or use tf.lite.TFLiteConverter with optimizations=[tf.lite.Optimize.DEFAULT] and specify supported_ops=[tf.lite.OpsSet.TFLITE_BUILTINS_INT8] after ensuring full integer quantization is possible."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/lite/performance/post_training_quantization",
  "official_doc_section": null,
  "error_code": "TQR",
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}