qkeras.qtools.quantized_operators.quantizer_impl

atomic quantizer implementation.

Functions

get_exp(quantizer)

get max/min exp value for relu_po2 or quantized_po2.

get_np_value(val)

Classes

Bernoulli()

bernoulli quantizer.

Binary([use_01])

binary quantizer.

FloatingPoint(bits)

float32.

IQuantizer()

abstract class for quantizer.

PowerOfTwo([is_signed])

po2.

QuantizedBits()

quantized bits.

QuantizedRelu()

quantized relu quantizer.

QuantizedTanh()

same as quantized bits.

QuantizedUlaw()

quantized ulaw type.

ReluPowerOfTwo()

relu po2.

StochasticBinary()

stochastic binary quantizer.

StochasticTernary()

stochastic ternary.

Ternary()

ternary(0, 1, -1).

class qkeras.qtools.quantized_operators.quantizer_impl.Bernoulli[source]

Bases: Binary

bernoulli quantizer. same as binary(0, 1).

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (bernoulli)

convert_to_qkeras_quantizer(alpha=None, temperature=6.0, use_real_sigmoid=True)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.Binary(use_01=False)[source]

Bases: IQuantizer

binary quantizer.

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (binary)

convert_to_qkeras_quantizer(alpha=None, use_stochastic_rounding=False)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.FloatingPoint(bits)[source]

Bases: IQuantizer

float32.

convert_qkeras_quantizer(bits)[source]
convert_to_qkeras_quantizer(bits)[source]
class qkeras.qtools.quantized_operators.quantizer_impl.IQuantizer[source]

Bases: ABC

abstract class for quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.PowerOfTwo(is_signed=True)[source]

Bases: IQuantizer

po2.

convert_qkeras_quantizer(quantizer)[source]

convert qkeras quantizer to qtools quantizer.

convert_to_qkeras_quantizer(negative_slope=0, use_stochastic_rounding=False, quadratic_approximation=False)[source]

convert qtools quantizer to qkeras quantizer.

get_min_max_exp()[source]
quantizer_bits_calculator(val)[source]

calculate how many bits needed.

update_inference_values(weights)[source]

find how many different values in weights in the po2 quantizer.

update_quantizer(val, reset=False)[source]

update quantizer bits according to the input value.

Parameters:
  • val – input value

  • reset – True->disregard current quantizer bits and reset it according to the given value; False-> update the quantizer bits with given value. quantizer.bits = min(existing_bits, bits required by val)

Returns:

Update existing po2 quantizer bits by val.

quantizer.bits = min(existing_bits, bits required by val)

class qkeras.qtools.quantized_operators.quantizer_impl.QuantizedBits[source]

Bases: IQuantizer

quantized bits.

mode

index of the current quantizer in MultiplierFactory.multiplier_impl_table

bits

total bits

int_bits

integer bits

is_signed

if a signed number

name

quantizer name

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (quantized_bits)

convert_to_qkeras_quantizer(symmetric=1, alpha=None, use_stochastic_rounding=False, scale_axis=None, qnoise_factor=1.0, elements_per_scale=None, min_po2_exponent=None, max_po2_exponent=None)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.QuantizedRelu[source]

Bases: IQuantizer

quantized relu quantizer.

convert_qkeras_quantizer(quantizer)[source]

convert from qkeras quantizer.

Parameters:

quantizer (quantized_relu)

convert_to_qkeras_quantizer(use_sigmoid=0, negative_slope=0.0, use_stochastic_rounding=False, relu_upper_bound=None, is_quantized_clip=True, qnoise_factor=1.0)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.QuantizedTanh[source]

Bases: QuantizedBits

same as quantized bits.

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (quantized_tanh)

convert_to_qkeras_quantizer(symmetric=False, use_stochastic_rounding=False)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.QuantizedUlaw[source]

Bases: QuantizedBits

quantized ulaw type.

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (quantized_ulaw)

convert_to_qkeras_quantizer(symmetric=0, u=255.0)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.ReluPowerOfTwo[source]

Bases: PowerOfTwo

relu po2.

convert_qkeras_quantizer(quantizer)[source]

convert qkeras quantizer to qtools quantizer.

Parameters:

quantizer (quantized_relu_po2)

convert_to_qkeras_quantizer(negative_slope=0, use_stochastic_rounding=False, quadratic_approximation=False)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.StochasticBinary[source]

Bases: Binary

stochastic binary quantizer.

convert_qkeras_quantizer(quantizer)[source]

convert qkeras quantizer to qtools quantizer.

Parameters:

quantizer (stochastic_binary)

convert_to_qkeras_quantizer(alpha=None, temperature=6.0, use_real_sigmoid=True)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.StochasticTernary[source]

Bases: Ternary

stochastic ternary.

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (stochastic_ternary)

convert_to_qkeras_quantizer(alpha=None, threshold=None, temperature=8.0, use_real_sigmoid=True, number_of_unrolls=5)[source]

convert qtools quantizer to qkeras quantizer.

class qkeras.qtools.quantized_operators.quantizer_impl.Ternary[source]

Bases: IQuantizer

ternary(0, 1, -1).

convert_qkeras_quantizer(quantizer)[source]
Parameters:

quantizer (ternary)

convert_to_qkeras_quantizer(alpha=None, threshold=None, use_stochastic_rounding=False, number_of_unrolls=5)[source]

convert qtools quantizer to qkeras quantizer.

qkeras.qtools.quantized_operators.quantizer_impl.get_exp(quantizer)[source]

get max/min exp value for relu_po2 or quantized_po2.

qkeras.qtools.quantized_operators.quantizer_impl.get_np_value(val)[source]