<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L374-L436) |

Quantize tensor based on min/max of tensor values with the fixed range.

Inherits From: [`Quantizer`](https://www.tensorflow.org/model_optimization/api_docs/python/tfmot/quantization/keras/quantizers/Quantizer)

    tfmot.quantization.keras.quantizers.FixedQuantizer(
        num_bits, init_min, init_max, narrow_range
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `num_bits` | Number of bits for quantization |
| `init_min` | the lower end of quantization interval. |
| `init_max` | the upper end of quantization interval. |
| `narrow_range` | In case of 8 bits, narrow_range nudges the quantized range to be \[-127, 127\] instead of \[-128, 127\]. This ensures symmetric range has 0 as the centre. |

<br />

## Methods

### `build`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L395-L396)

    build(
        tensor_shape, name, layer
    )

Construct the weights required by the quantizer.

A quantizer may need to construct variables to hold the state for its
algorithm. This function is invoked during the `build` stage of the layer
that the quantizer is used for. Any variables constructed are under the
scope of the `layer` and serialized as part of the layer.

<br />

<br />

<br />

| Args ||
|---|---|
| `tensor_shape` | Shape of tensor which needs to be quantized. |
| `name` | Name of tensor. |
| `layer` | Keras layer which is quantizing the tensors. The layer is needed to construct the weights, and is also the owner of the weights. |

<br />

Returns: Dictionary of constructed weights. This dictionary will be
passed to the quantizer's **call** function as a `weights` dictionary.

### `from_config`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L115-L125)

    @classmethod
    from_config(
        config
    )

Instantiates a `Quantizer` from its config.

<br />

<br />

<br />

| Args ||
|---|---|
| `config` | Output of `get_config()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A `Quantizer` instance. ||

<br />

### `get_config`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L418-L424)

    get_config()

Returns the config used to serialize the `Quantizer`.

### `__call__`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L398-L416)

    __call__(
        inputs, training, weights, **kwargs
    )

Quantize tensor.

<br />

<br />

<br />

| Args ||
|---|---|
| `inputs` | Input tensor to be quantized. |
| `training` | Whether the graph is currently training. |
| `weights` | Dictionary of weights the quantizer can use to quantize the tensor. This contains the weights created in the `build` function. |
| `**kwargs` | Additional variables which may be passed to the quantizer. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Quantized tensor. ||

<br />

### `__eq__`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L426-L433)

    __eq__(
        other
    )

Return self==value.

### `__ne__`

[View source](https://github.com/tensorflow/model-optimization/blob/v0.8.1/tensorflow_model_optimization/python/core/quantization/keras/quantizers.py#L435-L436)

    __ne__(
        other
    )

Return self!=value.