This example is used to demonstrate how to utilize Neural Compressor to enabling quantization and benchmark with python-flavor config.
pip install -r requirements.txtpython train.py- Run quantization
python test.py --tune- Run benchmark
python test.py --benchmark- Use python code to set necessary parameters.
from neural_compressor import conf
dataloader = {
'dataset': {'dummy_v2': {'input_shape': [28, 28]}}
}
conf.evaluation.performance.dataloader = dataloader
conf.quantization.calibration.dataloader = dataloader
conf.evaluation.accuracy.dataloader = dataloader
conf.tuning.accuracy_criterion.absolute = 0.9- Run quantization and benchmark.
from neural_compressor.experimental import Quantization, common
quantizer = Quantization(conf)
quantizer.model = common.Model("../models/frozen_graph.pb")
quantizer.fit()
from neural_compressor.experimental import Benchmark
evaluator = Benchmark(conf)
evaluator.model = common.Model("../models/frozen_graph.pb")
evaluator('performance')