<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/quantize.py#L145-L230) |

Annotate a `keras` model to be quantized.

    tfmot.quantization.keras.quantize_annotate_model(
        to_annotate
    )

### Used in the notebooks

| Used in the guide |
|---|
| - [Cluster preserving quantization aware training (CQAT) Keras example](https://www.tensorflow.org/model_optimization/guide/combine/cqat_example) - [Sparsity and cluster preserving quantization aware training (PCQAT) Keras example](https://www.tensorflow.org/model_optimization/guide/combine/pcqat_example) - [Pruning preserving quantization aware training (PQAT) Keras example](https://www.tensorflow.org/model_optimization/guide/combine/pqat_example) |

This function does not actually quantize the model. It merely specifies
that the model needs to be quantized. `quantize_apply` can then be used
to quantize the model.

This function is intended to be used in conjunction with the
`quantize_annotate_layer` API. Otherwise, it is simpler to use
`quantize_model`.

Annotate a model while overriding the default behavior for a layer:

    quantize_config = MyDenseQuantizeConfig()

    model = quantize_annotate_model(
      keras.Sequential([
        layers.Dense(10, activation='relu', input_shape=(100,)),
        quantize_annotate_layer(
            layers.Dense(2, activation='sigmoid'),
            quantize_config=quantize_config)
      ]))

    # The first Dense layer gets quantized with the default behavior,
    # but the second layer uses `MyDenseQuantizeConfig` for quantization.
    quantized_model = quantize_apply(model)

Note that this function removes the optimizer from the original model.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `to_annotate` | `keras` model which needs to be quantized. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| New keras model with each layer in the model wrapped with `QuantizeAnnotate`. The new model preserves weights from the original model. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if the model cannot be annotated. |

<br />