Skip to content

Latest commit

 

History

History
 
 

tf_example1

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

tf_example1 example

Step-by-Step

This example is used to demonstrate how to utilize Neural Compressor builtin dataloader and metric to enabling quantization without coding effort.

Prerequisite

1. Installation

pip install -r requirements.txt

Note: Validated TensorFlow Version.

2. Prepare Dataset

TensorFlow models repo provides scripts and instructions to download, process and convert the ImageNet dataset to the TF records format. We also prepared related scripts in TF image_recognition example.

3. Download the FP32 model

wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_6/mobilenet_v1_1.0_224_frozen.pb

Run

1. Run Command

python test.py --dataset_location=/path/to/imagenet/

2. Introduction

We only need to add the following lines for quantization to create an int8 model.

    from neural_compressor import Metric
    top1 = Metric(name="topk", k=1)
    config = PostTrainingQuantConfig(calibration_sampling_size=[20])
    q_model = fit(
        model="./mobilenet_v1_1.0_224_frozen.pb",
        conf=config,
        calib_dataloader=calib_dataloader,
        eval_dataloader=eval_dataloader,
        eval_metric=top1)