Examples/tensorflow/quantization/cle_bc.py
def aimet_bias_correction(sess: tf.Session, start_op_names: List[str], output_op_names: List[str],
                          data_loader, use_cuda: bool) -> tf.Session:
    """
    Applies Bias-Correction on the model.

    :param sess: The sess with graph to be evaluated
    :param start_op_names: The list of input op names of the sess.graph
    :param output_op_names: The list of output op names of the sess.graph
    :param data_loader: Input data loader class object
    :param use_cuda: If True then use a GPU for Bias Correction
    :return: The sess with graph after BC applied
    """

    # Quant scheme can be 'post_training_tf' or 'post_training_tf_enhanced'
    quant_mode = QuantScheme.post_training_tf_enhanced

    # Rounding mode can be 'nearest' or 'stochastic'
    rounding_mode = 'nearest'

    # Number of samples used during quantization
    num_quant_samples = 16

    # Number of samples used for bias correction
    num_bias_correct_samples = 16

    quant_params = aimet_bc.QuantParams(quant_mode=quant_mode, round_mode=rounding_mode,
                                        use_cuda=use_cuda, ops_to_ignore=[])
    bias_correction_params = aimet_bc.BiasCorrectionParams(batch_size=data_loader.batch_size,
                                                           num_quant_samples=num_quant_samples,
                                                           num_bias_correct_samples=num_bias_correct_samples,
                                                           input_op_names=start_op_names,
                                                           output_op_names=output_op_names)

    after_bc_sess = aimet_bc.BiasCorrection.correct_bias(sess, bias_correct_params=bias_correction_params,
                                                         quant_params=quant_params,
                                                         data_set=data_loader.dataset)

    return after_bc_sess

    Applies Bias-Correction on the model.

    :param sess: The sess with graph to be evaluated
    :param start_op_names: The list of input op names of the sess.graph
    :param output_op_names: The list of output op names of the sess.graph
    :param data_loader: Input data loader class object
    :param use_cuda: If True then use a GPU for Bias Correction
    :return: The sess with graph after BC applied
    
Applies Bias-Correction on the model.
Applies Bias - Correction on the model .
def aimet_bias_correction(sess: tf.Session, start_op_names: List[str], output_op_names: List[str],
                          data_loader, use_cuda: bool) -> tf.Session:
    quant_mode = QuantScheme.post_training_tf_enhanced
    rounding_mode = 'nearest'
    num_quant_samples = 16
    num_bias_correct_samples = 16
    quant_params = aimet_bc.QuantParams(quant_mode=quant_mode, round_mode=rounding_mode,
                                        use_cuda=use_cuda, ops_to_ignore=[])
    bias_correction_params = aimet_bc.BiasCorrectionParams(batch_size=data_loader.batch_size,
                                                           num_quant_samples=num_quant_samples,
                                                           num_bias_correct_samples=num_bias_correct_samples,
                                                           input_op_names=start_op_names,
                                                           output_op_names=output_op_names)
    after_bc_sess = aimet_bc.BiasCorrection.correct_bias(sess, bias_correct_params=bias_correction_params,
                                                         quant_params=quant_params,
                                                         data_set=data_loader.dataset)
    return after_bc_sess
def aimet_bias_correction ( sess : tf . Session , start_op_names : List [ str ] , output_op_names : List [ str ] , data_loader , use_cuda : bool ) -> tf . Session : quant_mode = QuantScheme . post_training_tf_enhanced rounding_mode = 'nearest' num_quant_samples = 16 num_bias_correct_samples = 16 quant_params = aimet_bc . QuantParams ( quant_mode = quant_mode , round_mode = rounding_mode , use_cuda = use_cuda , ops_to_ignore = [ ] ) bias_correction_params = aimet_bc . BiasCorrectionParams ( batch_size = data_loader . batch_size , num_quant_samples = num_quant_samples , num_bias_correct_samples = num_bias_correct_samples , input_op_names = start_op_names , output_op_names = output_op_names ) after_bc_sess = aimet_bc . BiasCorrection . correct_bias ( sess , bias_correct_params = bias_correction_params , quant_params = quant_params , data_set = data_loader . dataset ) return after_bc_sess
Applies Bias-Correction on the model.
Applies Bias - Correction on the model .
"""
    Applies Bias-Correction on the model.

    :param sess: The sess with graph to be evaluated
    :param start_op_names: The list of input op names of the sess.graph
    :param output_op_names: The list of output op names of the sess.graph
    :param data_loader: Input data loader class object
    :param use_cuda: If True then use a GPU for Bias Correction
    :return: The sess with graph after BC applied
    """ # Quant scheme can be 'post_training_tf' or 'post_training_tf_enhanced' # Rounding mode can be 'nearest' or 'stochastic' # Number of samples used during quantization # Number of samples used for bias correction
The sess with graph after BC applied
The sess with graph after BC applied
sess
tf.Session
The sess with graph to be evaluated
The sess with graph to be evaluated
start_op_names
List[str]
The list of input op names of the sess.graph
The list of input op names of the sess . graph
output_op_names
List[str]
The list of output op names of the sess.graph
The list of output op names of the sess . graph
data_loader
Input data loader class object
Input data loader class object
use_cuda
bool
If True then use a GPU for Bias Correction
If True then use a GPU for Bias Correction