cntk.contrib.netopt.quantization module

binarize_convolution(model, train_function, filter_function=None)[source]

Replace Convolution layers in the model to Halide implementations of binarized convolutions.

Parameters:
  • model – model that needs convolutions to be optimized.
  • train_function – this is a two step process. First, convert the model to binary convolution and next, transform it to the Halide implementation. Between above steps, we need to train the model to get the best results. train_function provides this functionality.
  • filter_function – filter layers in the model to apply the binarization.
Returns:

A model with Halid operators.

binary_convolution(filter_shape, num_filters=1, channels=1, init=<cntk.cntk_py.Dictionary; proxy of <Swig Object of type 'CNTK::ImageTransform *'> >, pad=False, strides=1, name='BinaryConvolution')[source]

Creates a binary convolution function based on the input parameters.

Parameters:
  • filter_shape – shape of the filter
  • num_filters – number of filters to use
  • init – initialization function for the filter
  • pad – padding enabled or not for the filter
  • strides – overlap for this filter
  • name – name given to the binary convolution.
Returns:

a function for performing binary convolution

convert_to_binary_convolution(model, filter_function=None)[source]

Replace convolution functions in the model with binary convolutions. The function replaces the convolution function inside the cntk.layers.convolution block without changing the block structure. The output model has python version of the binarized convolutions.

Parameters:
  • model – model that needs to be binarized.
  • filter_function – filter layers in the model to apply the binarization
Returns:

a model with convolution functions replaced by binary convolutions.

convert_to_native_binary_convolution(model)[source]

Clones a binary convolution network, sharing the original parameters but substitutes the python ‘BinaryConvolution’ Function instances used during training with faster C++ NativeBinaryConvolveFunction instances that uses optimized binary convolution implementations generated using the Halide framework

Parameters:model – model that needs convolutions to be substituted.
Returns:A model with Halid operators.