This example is used to demonstrate how to utilize Neural Compressor builtin dataloader and metric to enabling quantization without coding effort.
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
python test.py --dataset_location=/path/to/imagenet/
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)