Examples/torch/quantization/cle_bc.py
def calculate_quantsim_accuracy(model: torch.nn.Module, evaluator: aimet_common.defs.EvalFunction,
                                use_cuda: bool = False) -> float:
    """
    Calculates quantized model accuracy (INT8) using AIMET QuantizationSim

    :param model: the loaded model
    :param evaluator: the Eval function to use for evaluation
    :param use_cuda: True, if model is placed on GPU
    :return: quantized accuracy of model
    """
    input_shape = (1, image_net_config.dataset['image_channels'],
                   image_net_config.dataset['image_width'],
                   image_net_config.dataset['image_height'],)
    if use_cuda:
        dummy_input = torch.rand(input_shape).cuda()
    else:
        dummy_input = torch.rand(input_shape)

    # Number of batches to use for computing encodings
    # Only 5 batches are used here to speed up the process, also the
    # number of images in these 5 batches should be sufficient for
    # compute encodings
    iterations = 5

    quantsim = QuantizationSimModel(model=model, quant_scheme='tf_enhanced',
                                    dummy_input=dummy_input, rounding_mode='nearest',
                                    default_output_bw=8, default_param_bw=8, in_place=False)

    quantsim.compute_encodings(forward_pass_callback=partial(evaluator, use_cuda=use_cuda),
                               forward_pass_callback_args=iterations)

    accuracy = evaluator(quantsim.model, use_cuda=use_cuda)

    return accuracy

    Calculates quantized model accuracy (INT8) using AIMET QuantizationSim

    :param model: the loaded model
    :param evaluator: the Eval function to use for evaluation
    :param use_cuda: True, if model is placed on GPU
    :return: quantized accuracy of model
    
Calculates quantized model accuracy (INT8) using AIMET QuantizationSim
Calculates quantized model accuracy ( INT8 ) using AIMET QuantizationSim
def calculate_quantsim_accuracy(model: torch.nn.Module, evaluator: aimet_common.defs.EvalFunction,
                                use_cuda: bool = False) -> float:
    input_shape = (1, image_net_config.dataset['image_channels'],
                   image_net_config.dataset['image_width'],
                   image_net_config.dataset['image_height'],)
    if use_cuda:
        dummy_input = torch.rand(input_shape).cuda()
    else:
        dummy_input = torch.rand(input_shape)
    iterations = 5
    quantsim = QuantizationSimModel(model=model, quant_scheme='tf_enhanced',
                                    dummy_input=dummy_input, rounding_mode='nearest',
                                    default_output_bw=8, default_param_bw=8, in_place=False)
    quantsim.compute_encodings(forward_pass_callback=partial(evaluator, use_cuda=use_cuda),
                               forward_pass_callback_args=iterations)
    accuracy = evaluator(quantsim.model, use_cuda=use_cuda)
    return accuracy
def calculate_quantsim_accuracy ( model : torch . nn . Module , evaluator : aimet_common . defs . EvalFunction , use_cuda : bool = False ) -> float : input_shape = ( 1 , image_net_config . dataset [ 'image_channels' ] , image_net_config . dataset [ 'image_width' ] , image_net_config . dataset [ 'image_height' ] , ) if use_cuda : dummy_input = torch . rand ( input_shape ) . cuda ( ) else : dummy_input = torch . rand ( input_shape ) iterations = 5 quantsim = QuantizationSimModel ( model = model , quant_scheme = 'tf_enhanced' , dummy_input = dummy_input , rounding_mode = 'nearest' , default_output_bw = 8 , default_param_bw = 8 , in_place = False ) quantsim . compute_encodings ( forward_pass_callback = partial ( evaluator , use_cuda = use_cuda ) , forward_pass_callback_args = iterations ) accuracy = evaluator ( quantsim . model , use_cuda = use_cuda ) return accuracy
Calculates quantized model accuracy (INT8) using AIMET QuantizationSim
Calculates quantized model accuracy ( INT8 ) using AIMET QuantizationSim
"""
    Calculates quantized model accuracy (INT8) using AIMET QuantizationSim

    :param model: the loaded model
    :param evaluator: the Eval function to use for evaluation
    :param use_cuda: True, if model is placed on GPU
    :return: quantized accuracy of model
    """ # Number of batches to use for computing encodings # Only 5 batches are used here to speed up the process, also the # number of images in these 5 batches should be sufficient for # compute encodings
quantized accuracy of model
quantized accuracy of model
model
torch.nn.Module
the loaded model
the loaded model
evaluator
aimet_common.defs.EvalFunction
the Eval function to use for evaluation
the Eval function to use for evaluation
use_cuda
bool
True, if model is placed on GPU
True if model is placed on GPU