tf.keras.quantizers.fake_quant_with_min_max_vars

Perform per-tensor or per-channel fake quantization.

[min_vals, max_vals] define the clamping range for the inputs.

The inputs are quantized into the quantization range:

  • [0, 2^num_bits - 1] when narrow_range=False
  • [1, 2^num_bits - 1] when narrow_range=True

After quantization, the values are dequantized and output as floats within the [min_vals, max_vals] interval.

This operation supports gradient computation, allowing min_vals and max_vals to be trained.

inputs Input Keras tensor of float dtype.
min_vals A global minimum scalar or a per-channel minimum tensor.
max_vals A global maximum scalar or a per-channel maximum tensor.
num_bits Quantization bit width (e.g., 8 for int8). Defaults to 8.
narrow_range Whether to use narrow quantization range. Defaults to False.
axis Axis along which to perform per-channel quantization. If None, per-tensor quantization is performed. Defaults to None.

Tensor A Keras tensor with fake quantization applied.