tfmot.quantization.keras.quantize_annotate_layer
Stay organized with collections
Save and categorize content based on your preferences.
Annotate a tf.keras
layer to be quantized.
tfmot.quantization.keras.quantize_annotate_layer(
to_annotate, quantize_config=None
)
Used in the notebooks
This function does not actually quantize the layer. It is merely used to
specify that the layer should be quantized. The layer then gets quantized
accordingly when quantize_apply
is used.
This method should be used when the user wants to quantize only certain
layers of the model, or change the default behavior of how a layer is
quantized.
Annotate a layer:
model = keras.Sequential([
layers.Dense(10, activation='relu', input_shape=(100,)),
quantize_annotate_layer(layers.Dense(2, activation='sigmoid'))
])
# Only the second Dense layer is quantized.
quantized_model = quantize_apply(model)
Args |
to_annotate
|
tf.keras layer which needs to be quantized.
|
quantize_config
|
optional QuantizeConfig which controls how the layer is
quantized. In its absence, the default behavior for the layer is used.
|
Returns |
tf.keras layer wrapped with QuantizeAnnotate .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-05-26 UTC.
[null,null,["Last updated 2023-05-26 UTC."],[],[],null,["# tfmot.quantization.keras.quantize_annotate_layer\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/model-optimization/blob/v0.7.5/tensorflow_model_optimization/python/core/quantization/keras/quantize.py#L235-L285) |\n\nAnnotate a [`tf.keras`](https://www.tensorflow.org/api_docs/python/tf/keras) layer to be quantized. \n\n tfmot.quantization.keras.quantize_annotate_layer(\n to_annotate, quantize_config=None\n )\n\n### Used in the notebooks\n\n| Used in the guide |\n|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Quantization aware training comprehensive guide](https://www.tensorflow.org/model_optimization/guide/quantization/training_comprehensive_guide) |\n\nThis function does not actually quantize the layer. It is merely used to\nspecify that the layer should be quantized. The layer then gets quantized\naccordingly when `quantize_apply` is used.\n\nThis method should be used when the user wants to quantize only certain\nlayers of the model, or change the default behavior of how a layer is\nquantized.\n\n#### Annotate a layer:\n\n model = keras.Sequential([\n layers.Dense(10, activation='relu', input_shape=(100,)),\n quantize_annotate_layer(layers.Dense(2, activation='sigmoid'))\n ])\n\n # Only the second Dense layer is quantized.\n quantized_model = quantize_apply(model)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| `to_annotate` | [`tf.keras`](https://www.tensorflow.org/api_docs/python/tf/keras) layer which needs to be quantized. |\n| `quantize_config` | optional `QuantizeConfig` which controls how the layer is quantized. In its absence, the default behavior for the layer is used. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| [`tf.keras`](https://www.tensorflow.org/api_docs/python/tf/keras) layer wrapped with `QuantizeAnnotate`. ||\n\n\u003cbr /\u003e"]]