This example is used to demonstrate how to configure benchmark using pure python API for performance measurement.
pip install -r requirements.txt
Note: Validated TensorFlow Version.
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.
wget https://storage.googleapis.com/intel-optimized-tensorflow/models/v1_6/mobilenet_v1_1.0_224_frozen.pb
- 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/
- We only need to add the following lines for quantization to create an int8 model.
from neural_compressor.quantization import fit
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)
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=1)
fit(model='./int8.pb', conf=conf, b_dataloader=eval_dataloader)