qkeras.qtools.qtools_util
utility functions.
Functions
|
Adjust accumulator when weight quantizer is auto_po2 type. |
|
Adjust multiplier when weight quantizer is auto_po2 type. |
|
|
|
get the current layer's input quantizer. |
|
get input quantizer, deal with keras layer or lack of input quantizer in qkeras layer. |
|
|
|
Determines number of multiplier operations in a qkeras layer. |
Get scale from quantized_bits with alpha=auto_po2. |
|
|
|
|
Get layer weights. |
|
|
|
|
|
- qkeras.qtools.qtools_util.adjust_accumulator_for_auto_po2(layer, multiplier, qkeras_weight_quantizer, bias_quantizer)[source]
Adjust accumulator when weight quantizer is auto_po2 type.
- qkeras.qtools.qtools_util.adjust_multiplier_for_auto_po2(multiplier, qkeras_weight_quantizer)[source]
Adjust multiplier when weight quantizer is auto_po2 type.
Multiplier_bits = bits_x + bits_w Multiplier_intbits = log2(scale) + intbits_x + intbits_w
Because we might have different scale for auto_po2 quantizer at different output channels, multiplier will have different integer bits at different output channel accordingly, which is not desirable in hardware implementation. Therefore we set a general multiplier quantizers so that it provides enough fractional bits and integer bits for all output channels.
- qkeras.qtools.qtools_util.get_input_quantizers(graph, node_id, quantizer_factory, debug=False)[source]
get the current layer’s input quantizer.
- qkeras.qtools.qtools_util.get_input_quantizers_advanced(graph, node_id, is_input_layer, quantizer_factory, cfg, debug=False)[source]
get input quantizer, deal with keras layer or lack of input quantizer in qkeras layer.
- qkeras.qtools.qtools_util.get_layer_info(layer, attr_name)[source]
- Parameters:
layer (Layer)
attr_name (str)
- qkeras.qtools.qtools_util.get_operation_count(layer, input_shape)[source]
Determines number of multiplier operations in a qkeras layer.
- qkeras.qtools.qtools_util.get_scale_from_quantized_bits_with_auto_po2(quantizer)[source]
Get scale from quantized_bits with alpha=auto_po2.
- qkeras.qtools.qtools_util.get_weights(layer, model_weights_already_quantized=True)[source]
Get layer weights.
- Parameters:
layer – given qkeras/keras layer
model_weights_already_quantized – bool. whether the given layer’s weights are already quantized. This is necessary because with certain quantizers, eg., quantized_bits(alpha=”auto_po2”), we cannot quantize the same weights more than once, as it will lead to different results.
- Returns:
Quantized layer weights.