tfmot.quantization.keras.quantize_annotate_model
Stay organized with collections
Save and categorize content based on your preferences.
Annotate a tf.keras
model to be quantized.
tfmot.quantization.keras.quantize_annotate_model(
to_annotate
)
Used in the notebooks
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.
Args |
to_annotate
|
tf.keras model which needs to be quantized.
|
Returns |
New tf.keras model with each layer in the model wrapped with
QuantizeAnnotate . The new model preserves weights from the original
model.
|
Raises |
ValueError
|
if the model cannot be annotated.
|
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.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2023-05-26 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-05-26 UTC."],[],[]]