edgeai-mmdetection icon indicating copy to clipboard operation
edgeai-mmdetection copied to clipboard

the rusult of QAT model in .onnx and .pt are much different

Open wcyjerry opened this issue 1 year ago • 8 comments

When training done with fp32, I convert the .pt model to .onnx, and I respectively use them to predict one pic, and the results are very close. While when I QAT this model, and doing the same step, the results are much different. Is this something wrong during the convert process? Should there be any more attentions when convert a QAT model to onnx? Thx

wcyjerry avatar May 25 '23 08:05 wcyjerry

When training done with fp32, I convert the .pt model to .onnx, and I respectively use them to predict one pic, and the results are very close

QAT onnx model from QuantTrainModule() is meant to be used with TIDL (i.e. with onnxruntime-tidl and with parameters set correctly for QAT model calibration) If you use regular onnxruntime, it would try to do a float inference in this QAT model and the result would not be good.

mathmanu avatar May 26 '23 10:05 mathmanu

When training done with fp32, I convert the .pt model to .onnx, and I respectively use them to predict one pic, and the results are very close

QAT onnx model from QuantTrainModule() is meant to be used with TIDL (i.e. with onnxruntime-tidl and with parameters set correctly for QAT model calibration) If you use regular onnxruntime, it would try to do a float inference in this QAT model and the result would not be good.

Thx, I get. One more question: eg. I'm using yolox of edgeai-mmdetection to do QAT, maybe like 12 epoch, after training done it will do evaluation on test set, if I get a map50 like 0.80, then I convert this model to a .onnx, and I used it on onnxruntime-tidl, will the result be same or close to 0.80?

wcyjerry avatar May 29 '23 02:05 wcyjerry

That is the expectation, getting exact accuracy involves a lot of aspects including using the correct confidence threshold, top-k boxes, input pre-processing etc. So, do don't think it will be easy to match the accuracy exactly.

mathmanu avatar May 29 '23 04:05 mathmanu

That is the expectation, getting exact accuracy involves a lot of aspects including using the correct confidence threshold, top-k boxes, input pre-processing etc. So, do don't think it will be easy to match the accuracy exactly.

Export QAT model just using regular method like torch.onnx.export is ok?

wcyjerry avatar May 29 '23 07:05 wcyjerry

Yes - you can see details here: https://github.com/TexasInstruments/edgeai-torchvision/blob/master/docs/pixel2pixel/Quantization.md#how-to-use--quanttrainmodule

mathmanu avatar May 29 '23 07:05 mathmanu

Yes - you can see details here: https://github.com/TexasInstruments/edgeai-torchvision/blob/master/docs/pixel2pixel/Quantization.md#how-to-use--quanttrainmodule

I'm very new to this area, now I have a trained QAT model, and the map I get during QAT on test set is like 0.68 (only drop 0.02 compared to fp32 pretrained model), I want to double-check the infer result, is there any doc about how to use this QAT model correctly like using onnxruntime-tidl u mentioned?

wcyjerry avatar May 29 '23 08:05 wcyjerry

Accuracy benchmark is provided via: https://github.com/TexasInstruments/edgeai-benchmark

See the instructions to compile custom models: https://github.com/TexasInstruments/edgeai-benchmark/blob/master/docs/custom_models.md

mathmanu avatar May 29 '23 08:05 mathmanu

Thanks a lot. I'll check it, good day!

wcyjerry avatar May 29 '23 08:05 wcyjerry