Supported and tested layers

qDense class

class quantizer.qDense.QDense(*args, **kwargs)[source]

Bases: Dense, PrunableLayer

Implements a quantized Dense layer.

call(inputs)[source]
compute_output_shape(input_shape)[source]

Computes the output shape of the layer.

This method will cause the layer’s state to be built, if that has not happened before. This requires that the layer will later be used with inputs that match the input shape provided here.

Parameters:

input_shape – Shape tuple (tuple of integers) or tf.TensorShape, or structure of shape tuples / tf.TensorShape instances (one per output tensor of the layer). Shape tuples can include None for free dimensions, instead of an integer.

Returns:

A tf.TensorShape instance or structure of tf.TensorShape instances.

get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

get_prunable_weights()[source]

Returns list of prunable weight tensors.

All the weight tensors which the layer wants to be pruned during training must be returned by this method.

Returns: List of weight tensors/kernels in the keras layer which must be

pruned during training.

get_quantization_config()[source]
get_quantizers()[source]

qconvolutional class

class quantizer.qconvolutional.QConv2D(*args, **kwargs)[source]

Bases: Conv2D, PrunableLayer

2D convolution layer (e.g. spatial convolution over images).

most of these parameters follow the implementation of Conv2D in Keras, with the exception of kernel_range, bias_range, kernel_quantizer and bias_quantizer, and kernel_initializer.

kernel_quantizer: quantizer function/class for kernel bias_quantizer: quantizer function/class for bias kernel_range/bias_ranger: for quantizer functions whose values can go over [-1,+1], these values are used to set the clipping value of kernels and biases, respectively, instead of using the constraints specified by the user.

we refer the reader to the documentation of Conv2D in Keras for the other parameters.

call(inputs)[source]
get_config()[source]

Returns the config of the layer.

A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.

The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).

Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.

Returns:

Python dictionary.

get_prunable_weights()[source]

Returns list of prunable weight tensors.

All the weight tensors which the layer wants to be pruned during training must be returned by this method.

Returns: List of weight tensors/kernels in the keras layer which must be

pruned during training.

get_quantization_config()[source]
get_quantizers()[source]