Skip to content

Latest commit

 

History

History
48 lines (41 loc) · 1.78 KB

File metadata and controls

48 lines (41 loc) · 1.78 KB

tf_example5 example

This example is used to demonstrate how to config benchmark using pure python API for performance measurement.

1. Installation

pip install -r requirements.txt

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

5. Run Command

  • Run quantization
python test.py --tune --dataset_location=/path/to/imagenet/
  • Run benchmark, please make sure benchmark the model should after tuning.
python test.py --benchmark --dataset_location=/path/to/imagenet/

6. Introduction

  • We only need to add the following lines for quantization to create an int8 model.
    from neural_compressor.quantization import fit
    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)
    q_model.save('./int8.pb')
  • Run benchmark according to config.
    from neural_compressor.benchmark import fit
    conf = BenchmarkConfig(iteration=100, cores_per_instance=4, num_of_instance=7)
    fit(model='./int8.pb', config=conf, b_dataloader=eval_dataloader)