tfmot.quantization.keras.quantize_model
Stay organized with collections
Save and categorize content based on your preferences.
Quantize a tf.keras
model with the default quantization implementation.
tfmot.quantization.keras.quantize_model(
to_quantize, quantized_layer_name_prefix='quant_'
)
Used in the notebooks
Quantization constructs a model which emulates quantization during training.
This allows the model to learn parameters robust to quantization loss, and
also model the accuracy of a quantized model.
For more information, see
https://www.tensorflow.org/model_optimization/guide/quantization/training
Quantize a model:
# Quantize sequential model
model = quantize_model(
keras.Sequential([
layers.Dense(10, activation='relu', input_shape=(100,)),
layers.Dense(2, activation='sigmoid')
]))
# Quantize functional model
in = tf.keras.Input((3,))
out = tf.keras.Dense(2)(in)
model = tf.keras.Model(in, out)
quantized_model = quantize_model(model)
Note that this function removes the optimizer from the original model.
The returned model copies over weights from the original model. So while
it preserves the original weights, training it will not modify the weights
of the original model.
Args |
to_quantize
|
tf.keras model to be quantized. It can have pre-trained
weights.
|
quantized_layer_name_prefix
|
Name prefix for the quantized layers. The
default is quant_ .
|
Returns |
Returns a new tf.keras model prepared for quantization.
|
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."]]