tfmot.quantization.keras.quantizers.MovingAverageQuantizer

Quantize tensor based on a moving average of values across batches.

Inherits From: Quantizer

num_bitsNumber of bits for quantization
per_axisWhether to apply per_axis quantization. The last dimension is used as the axis.
symmetricIf true, use symmetric quantization limits instead of training the minimum and maximum of each quantization range separately.
narrow_rangeIn case of 8 bits, narrow_range nudges the quantized range to be [-127, 127] instead of [-128, 127]. This ensures symmetric range has 0 as the centre.

Methods

build

View source

Construct the weights required by the quantizer.

A quantizer may need to construct variables to hold the state for its algorithm. This function is invoked during the build stage of the layer that the quantizer is used for. Any variables constructed are under the scope of the layer and serialized as part of the layer.

Args
tensor_shapeShape of tensor which needs to be quantized.
nameName of tensor.
layerKeras layer which is quantizing the tensors. The layer is needed to construct the weights, and is also the owner of the weights.

Returns: Dictionary of constructed weights. This dictionary will be passed to the quantizer's call function as a weights dictionary.

from_config

View source

Instantiates a Quantizer from its config.

Args
configOutput of get_config().

Returns
A Quantizer instance.

get_config

View source

Returns the config used to serialize the Quantizer.

__call__

View source

Quantize tensor.

Args
inputsInput tensor to be quantized.
trainingWhether the graph is currently training.
weightsDictionary of weights the quantizer can use to quantize the tensor. This contains the weights created in the build function.
**kwargsAdditional variables which may be passed to the quantizer.

Returns
Quantized tensor.

__eq__

View source

Return self==value.

__ne__

View source

Return self!=value.