Google I / O에서 기조 연설, 제품 세션, 워크샵 등을 시청 하세요. 재생 목록보기


Quantize a tf.keras model with the default quantization implementation.

Used in the notebooks

Used in the guide

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

Quantize a model:

# Quantize sequential model
model = quantize_model(
        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.

to_quantize tf.keras model to be quantized. It can have pre-trained weights.

Returns a new tf.keras model prepared for quantization.