Hello, I am trying to export the Faster RCNN model from PyTorch after performing quantization on the backbone:
import torchvision
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=False)
example_input = torch.randn(1, 3, 224, 224)
model.eval()
model.backbone = quantize_fx.fuse_fx(model.backbone) # The modules of the model are fused
model.train() # The model needs to be set to train before preparation for QAT
qconfig_mapping = get_default_qconfig_mapping("fbgemm")
model.backbone = quantize_fx.prepare_qat_fx(model.backbone, qconfig_mapping, example_input)
model.backbone = quantize_fx.convert_fx(model.backbone)
model.eval()
torch.onnx.export(model,
example_input,
"fast_rcnn.onnx",
verbose=False,
input_names=['input'],
output_names=['output'],
export_params=True,
opset_version=13
)
When I run the onnx export, I get the error:
RuntimeError: Type 'Tuple[Tensor, NoneType]' cannot be traced. Only Tensors and (possibly nested) Lists, Dicts, and Tuples of Tensors can be traced
Meanwhile, I do not get this error when I am exporting the un-quantized model. Thank you very much for your help.