# ValueError：操作'CONV_2D'的量化范围（最小值、最大值）不支持输入类型float32和输出类型uint8

- **ID:** `tensorflow/tflite-quantization-range`
- **领域:** tensorflow
- **类别:** build_error
- **错误码:** `TQR`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在TFLite转换过程中，CONV_2D操作的量化参数（最小值/最大值）缺失或超出uint8量化的有效范围，通常是因为校准数据未覆盖完整的激活范围。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| tensorflow>=2.12.0 | active | — | — |
| tflite>=2.12 | active | — | — |
| python>=3.9 | active | — | — |

## 解决方案

1. ```
   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).
   ```
2. ```
   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.
   ```

## 无效尝试

- **Increasing the number of calibration steps arbitrarily without verifying data diversity.** — More steps of the same data does not improve range coverage; the error persists if the calibration set lacks extreme values. (70% 失败率)
- **Manually setting min/max to [-128, 127] in the converter options.** — TFLite converter ignores manual override for per-op ranges; it expects calibration to provide them. (90% 失败率)
