Could not run ''

this code uses resnet and tries to quantize a CNN. The exception is ‘NotImplementedError: Could not run ‘’ with arguments from the ‘CPU’ backend.’

What you are trying to do is process images (that are torch.float32 on CPU device/backend) with quantized model (with all operations quantized to torch.qint8(? or quint8 I don’t remember) on QuantizedCPU device/backend).
I believe that modifying model is necessary - especially entry and exit points. You can use PyTorch’s implementation of ResNet: vision/torchvision/models/quantization/ at main · pytorch/vision · GitHub.

Therefore changing single line 24. to:

model = torchvision.models.quantization.resnet18(pretrained=True)

should be enough. Although I would check how they are fusing model.

you get that error if you do eager mode quantization without adding quant stubs to the model

see Quantization — PyTorch 2.2 documentation