I am using the ONNX-Python-library. I am trying to quantize ai-models statically using the quantize_static() function imported from onnxruntime.quantization.
This function takes a calibration_data_reader-object as the third input, and I could not find a comprehensive explanation what this object is, or how to create one.
How could I create this object? Also, would it be possible to create a generic version of the calibrationDataReader, that can be used by multiple models?
I have tried looking this up on the onnx-website and reading through examples for this on the github-page, but cannot find an explanation or documentation I can understand, as most datareaders seem to be pre-made specific to a model.
The best thing I could think of, was something like this, using a calibrator from the onnx.quantization-tools:
from onnxruntime.quantization import quantize_static, calibrate
def quantize(model_path, output_path):
calibrator = calibrate.create_calibrator(model_path, calibrate_method= calibrate.CalibrationMethod.MinMax)
quantize_static(model_input= model_path, model_output= output_path, calibration_data_reader= calibrator)
Which throws this error:
quantize_static(model_input= model_path, model_output= output_path, calibration_data_reader= calibrator)
File "████PythonPython311Libsite-packagesonnxruntimequantizationquantize.py", line 435, in quantize_static
calibrator.collect_data(calibration_data_reader)
File "████PythonPython311Libsite-packagesonnxruntimequantizationcalibrate.py", line 301, in collect_data
inputs = data_reader.get_next()
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MinMaxCalibrater' object has no attribute 'get_next'
I am probably using the wrong type of object here, but I am out of ideas. An explanation or link to a resource explaining the topic would help me with this.