View source on GitHub |
Quantize tensor based on a moving average of values across batches.
Inherits From: Quantizer
tfmot.quantization.keras.quantizers.MovingAverageQuantizer(
num_bits, per_axis, symmetric, narrow_range
)
Methods
build
build(
tensor_shape, name, layer
)
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_shape
|
Shape of tensor which needs to be quantized. |
name
|
Name of tensor. |
layer
|
Keras 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
@classmethod
from_config( config )
Instantiates a Quantizer
from its config.
Args | |
---|---|
config
|
Output of get_config() .
|
Returns | |
---|---|
A Quantizer instance.
|
get_config
get_config()
Returns the config used to serialize the Quantizer
.
__call__
__call__(
inputs, training, weights, **kwargs
)
Quantize tensor.
Args | |
---|---|
inputs
|
Input tensor to be quantized. |
training
|
Whether the graph is currently training. |
weights
|
Dictionary of weights the quantizer can use to quantize the
tensor. This contains the weights created in the build function.
|
**kwargs
|
Additional variables which may be passed to the quantizer. |
Returns | |
---|---|
Quantized tensor. |
__eq__
__eq__(
other
)
Return self==value.
__ne__
__ne__(
other
)
Return self!=value.