diff --git a/torchvision/models/quantization/mobilenetv3.py b/torchvision/models/quantization/mobilenetv3.py index f8fe39ed195..2d18446c13f 100644 --- a/torchvision/models/quantization/mobilenetv3.py +++ b/torchvision/models/quantization/mobilenetv3.py @@ -140,6 +140,10 @@ def _mobilenet_v3_model( _replace_relu(model) if quantize: + # Instead of quantizing the model and then loading the quantized weights we take a different approach. + # We prepare the QAT model, load the QAT weights from training and then convert it. + # This is done to avoid extremely low accuracies observed on the specific model. This is rather a workaround + # for an unresolved bug on the eager quantization API detailed at: https://github.com/pytorch/vision/issues/5890 model.fuse_model(is_qat=True) model.qconfig = torch.ao.quantization.get_default_qat_qconfig(backend) torch.ao.quantization.prepare_qat(model, inplace=True)