Accuracy of Quantized model drop very much compare with normal model

I am a newbie of quantization. I trained a Resnet model and quantized it by using this instruction
The original model possesses 96% accuracy, however, model_quantized got 49% accuracy. Why this happened and how can I address it? Thank all of you

Quantize model (post-training Static quantization FX Graph mode)

torch.backends.quantized.engine = “x86”“cpu”)

prepared_model = prepare_fx(model, {“”: get_default_qconfig(“x86”)})

with torch.no_grad(): # calibrate using random data

  data = torch.rand((7,1,10,20))

model_quantized = convert_fx(prepared_model)

Hi @kent252

This is expected if you calibrate using random data. During calibration we calculate the optimal scales and zero_point using the data provided. Can you try calibrating on the representative input data of whatever dataset you are using to evaluate accuracy?

1 Like

Thank you for your information. I appreciate