<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#L34-L80) |

Scope which can be used to deserialize quantized Keras models and layers.

    tfmot.quantization.keras.quantize_scope(
        *args
    )

### Used in the notebooks

| Used in the guide |
|---|
| - [Quantization aware training comprehensive guide](https://www.tensorflow.org/model_optimization/guide/quantization/training_comprehensive_guide) |

Under `quantize_scope`, Keras methods such as `keras.load_model` and
`keras.models.model_from_config` will be able to deserialize Keras models
and layers which contain quantization classes such as `QuantizeConfig`
and `Quantizer`.

#### Example:

    keras.models.save_model(quantized_model, keras_file)

    with quantize_scope():
      loaded_model = keras.models.load_model(keras_file)

    # If your quantized model uses custom objects such as a specific `Quantizer`,
    # you can pass them to quantize_scope to deserialize your model.
    with quantize_scope({'FixedRangeQuantizer', FixedRangeQuantizer}
      loaded_model = keras.models.load_model(keras_file)

For further understanding, see [`keras.utils.custom_object_scope`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/CustomObjectScope).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `*args` | Variable length list of dictionaries of `{name, class}` pairs to add to the scope created by this method. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Object of type `CustomObjectScope` with quantization objects included. ||

<br />