I want to quantize my model to load on a rasberrry pi for fast inference and I am using a pre-trained model and am getting this error. How can I go about resolving this issue?
#Static quantization of torch model
model_tp = torch.hub.load('yangsenius/TransPose:main',
'tph_a4_256x192',
pretrained=True)
model_tp.final_layer = torch.nn.Sequential(torch.nn.Conv2d(96, 16, kernel_size=1))
model = model_tp.to(device)
x = torch.randn(1,3,256,192).to(device, dtype=float)
print(f"Output shape from model is: {model(x.float()).shape}")
quant_model = model
backend = "qnnpack"
quant_model.qconfig = torch.quantization.get_default_qconfig(backend)
torch.backends.quantized.engine = backend
model_static_quantized = torch.quantization.prepare(quant_model, inplace=False)
model_static_quantized = torch.quantization.convert(model_static_quantized, inplace=False)
NotImplementedError Traceback (most recent call last)
in ()
9 image = inp_img.squeeze(0).permute(1,2,0).cpu().detach().numpy()
10
—> 11 output = model_static_quantized(inp_img)
12 output = np.expand_dims(output[0].cpu().detach().numpy(),0)
13
3 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/quantized/modules/conv.py in forward(self, input)
424 mode=self.padding_mode)
425 return ops.quantized.conv2d(
→ 426 input, self._packed_params, self.scale, self.zero_point)
427
428 @classmethod
NotImplementedError: Could not run ‘quantized::conv2d.new’ with arguments from the ‘CPU’ backend. This could be because the operator doesn’t exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit Internal Login for possible resolutions. ‘quantized::conv2d.new’ is only available for these backends: [QuantizedCPU, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].
QuantizedCPU: registered at …/aten/src/ATen/native/quantized/cpu/qconv.cpp:883 [kernel]
BackendSelect: fallthrough registered at …/aten/src/ATen/core/BackendSelectFallbackKernel.cpp:3 [backend fallback]
Python: registered at …/aten/src/ATen/core/PythonFallbackKernel.cpp:47 [backend fallback]
Named: registered at …/aten/src/ATen/core/NamedRegistrations.cpp:7 [backend fallback]
Conjugate: registered at …/aten/src/ATen/ConjugateFallback.cpp:18 [backend fallback]
Negative: registered at …/aten/src/ATen/native/NegateFallback.cpp:18 [backend fallback]
ADInplaceOrView: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:64 [backend fallback]
AutogradOther: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:35 [backend fallback]
AutogradCPU: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:39 [backend fallback]
AutogradCUDA: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:47 [backend fallback]
AutogradXLA: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:51 [backend fallback]
AutogradLazy: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:55 [backend fallback]
AutogradXPU: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:43 [backend fallback]
AutogradMLC: fallthrough registered at …/aten/src/ATen/core/VariableFallbackKernel.cpp:59 [backend fallback]
Tracer: registered at …/torch/csrc/autograd/TraceTypeManual.cpp:291 [backend fallback]
UNKNOWN_TENSOR_TYPE_ID: fallthrough registered at …/aten/src/ATen/autocast_mode.cpp:466 [backend fallback]
Autocast: fallthrough registered at …/aten/src/ATen/autocast_mode.cpp:305 [backend fallback]
Batched: registered at …/aten/src/ATen/BatchingRegistrations.cpp:1016 [backend fallback]
VmapMode: fallthrough registered at …/aten/src/ATen/VmapModeRegistrations.cpp:33 [backend fallback]