Examples/torch/quantization/adaround.py
def adaround_example(config: argparse.Namespace):
    """
    1. Instantiates Data Pipeline for evaluation
    2. Loads the pretrained resnet18 Pytorch model
    3. Calculates Model accuracy
        3.1. Calculates floating point accuracy
        3.2. Calculates Quant Simulator accuracy
    4. Applies AIMET CLE and BC
        4.1. Applies AIMET CLE and calculates QuantSim accuracy
        4.2. Applies AIMET BC and calculates QuantSim accuracy

    :param config: This argparse.Namespace config expects following parameters:
                   tfrecord_dir: Path to a directory containing ImageNet TFRecords.
                                This folder should conatin files starting with:
                                'train*': for training records and 'validation*': for validation records
                   use_cuda: A boolean var to indicate to run the test on GPU.
                   logdir: Path to a directory for logging.
    """

    # Instantiate Data Pipeline for evaluation and training
    data_pipeline = ImageNetDataPipeline(config)

    # Load the pretrained resnet18 model
    model = models.resnet18(pretrained=True)
    if config.use_cuda:
        model.to(torch.device('cuda'))
    model = model.eval()

    # Calculate FP32 accuracy
    accuracy = data_pipeline.evaluate(model, use_cuda=config.use_cuda)
    logger.info("Original Model top-1 accuracy = %.2f", accuracy)
    logger.info("Applying Adaround")

    # Applying Adaround
    # Optimally rounds the parameters of the model
    data_loader = ImageNetDataLoader(is_training=False, images_dir=config.dataset_dir,
                                     image_size=image_net_config.dataset['image_size']).data_loader
    accuracy = apply_adaround_and_find_quantized_accuracy(model=model, evaluator=data_pipeline.evaluate,
                                                          data_loader=data_loader, use_cuda=config.use_cuda,
                                                          logdir=config.logdir)

    logger.info("After applying Adaround, top-1 accuracy = %.2f", accuracy)
    logger.info("Adaround Complete")

    1. Instantiates Data Pipeline for evaluation
    2. Loads the pretrained resnet18 Pytorch model
    3. Calculates Model accuracy
        3.1. Calculates floating point accuracy
        3.2. Calculates Quant Simulator accuracy
    4. Applies AIMET CLE and BC
        4.1. Applies AIMET CLE and calculates QuantSim accuracy
        4.2. Applies AIMET BC and calculates QuantSim accuracy

    :param config: This argparse.Namespace config expects following parameters:
                   tfrecord_dir: Path to a directory containing ImageNet TFRecords.
                                This folder should conatin files starting with:
                                'train*': for training records and 'validation*': for validation records
                   use_cuda: A boolean var to indicate to run the test on GPU.
                   logdir: Path to a directory for logging.
    
1. Instantiates Data Pipeline for evaluation
2. Loads the pretrained resnet18 Pytorch model
3.
1 . Instantiates Data Pipeline for evaluation 2 . Loads the pretrained resnet18 Pytorch model 3 .
def adaround_example(config: argparse.Namespace):
    data_pipeline = ImageNetDataPipeline(config)
    model = models.resnet18(pretrained=True)
    if config.use_cuda:
        model.to(torch.device('cuda'))
    model = model.eval()
    accuracy = data_pipeline.evaluate(model, use_cuda=config.use_cuda)
    logger.info("Original Model top-1 accuracy = %.2f", accuracy)
    logger.info("Applying Adaround")
    data_loader = ImageNetDataLoader(is_training=False, images_dir=config.dataset_dir,
                                     image_size=image_net_config.dataset['image_size']).data_loader
    accuracy = apply_adaround_and_find_quantized_accuracy(model=model, evaluator=data_pipeline.evaluate,
                                                          data_loader=data_loader, use_cuda=config.use_cuda,
                                                          logdir=config.logdir)
    logger.info("After applying Adaround, top-1 accuracy = %.2f", accuracy)
    logger.info("Adaround Complete")
def adaround_example ( config : argparse . Namespace ) : data_pipeline = ImageNetDataPipeline ( config ) model = models . resnet18 ( pretrained = True ) if config . use_cuda : model . to ( torch . device ( 'cuda' ) ) model = model . eval ( ) accuracy = data_pipeline . evaluate ( model , use_cuda = config . use_cuda ) logger . info ( "Original Model top-1 accuracy = %.2f" , accuracy ) logger . info ( "Applying Adaround" ) data_loader = ImageNetDataLoader ( is_training = False , images_dir = config . dataset_dir , image_size = image_net_config . dataset [ 'image_size' ] ) . data_loader accuracy = apply_adaround_and_find_quantized_accuracy ( model = model , evaluator = data_pipeline . evaluate , data_loader = data_loader , use_cuda = config . use_cuda , logdir = config . logdir ) logger . info ( "After applying Adaround, top-1 accuracy = %.2f" , accuracy ) logger . info ( "Adaround Complete" )
1.
1 .
"""
    1. Instantiates Data Pipeline for evaluation
    2. Loads the pretrained resnet18 Pytorch model
    3. Calculates Model accuracy
        3.1. Calculates floating point accuracy
        3.2. Calculates Quant Simulator accuracy
    4. Applies AIMET CLE and BC
        4.1. Applies AIMET CLE and calculates QuantSim accuracy
        4.2. Applies AIMET BC and calculates QuantSim accuracy

    :param config: This argparse.Namespace config expects following parameters:
                   tfrecord_dir: Path to a directory containing ImageNet TFRecords.
                                This folder should conatin files starting with:
                                'train*': for training records and 'validation*': for validation records
                   use_cuda: A boolean var to indicate to run the test on GPU.
                   logdir: Path to a directory for logging.
    """ # Instantiate Data Pipeline for evaluation and training # Load the pretrained resnet18 model # Calculate FP32 accuracy # Applying Adaround # Optimally rounds the parameters of the model
config
argparse.Namespace
This argparse.Namespace config expects following parameters:
tfrecord_dir: Path to a directory containing ImageNet TFRecords.
This folder should conatin files starting with:
'train*': for training records and 'validation*': for validation records
use_cuda: A boolean var to indicate to run the test on GPU.
logdir: Path to a directory for logging.
This argparse . Namespace config expects following parameters : tfrecord_dir : Path to a directory containing ImageNet TFRecords . This folder should conatin files starting with : ' train * ' : for training records and ' validation * ' : for validation records use_cuda : A boolean var to indicate to run the test on GPU . logdir : Path to a directory for logging .