pytorch / ao

PyTorch native quantization and sparsity for training and inference
BSD 3-Clause "New" or "Revised" License
1.59k stars 177 forks source link

RuntimeError: Error(s) in loading state_dict for QuantizedFasterRCNN: #1123

Open adityapandey369 opened 1 month ago

adityapandey369 commented 1 month ago

I have fine-tuned and quantized faster_rcnn model for the use but when I load it...

RuntimeError Traceback (most recent call last) in <cell line: 10>() 8 9 # Load the quantized model weights ---> 10 quantized_model.load_state_dict(torch.load('/content/drive/MyDrive/Aditya Pandey/global_wheat_detection-2-20241004T044942Z-001/global_wheat_detection-2/Copy of faster_rcnn_40MB.pth', map_location=torch.device('cpu'))) 11 12 # Set the model to evaluation mode

/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict, assign) 2213 2214 if len(error_msgs) > 0: -> 2215 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( 2216 self.class.name, "\n\t".join(error_msgs))) 2217 return _IncompatibleKeys(missing_keys, unexpected_keys)

RuntimeError: Error(s) in loading state_dict for QuantizedFasterRCNN: Missing key(s) in state_dict: "model.backbone.body.conv1.weight", "model.backbone.body.bn1.weight", "model.backbone.body.bn1.bias", "model.backbone.body.bn1.running_mean", "model.backbone.body.bn1.running_var", "model.backbone.body.layer1.0.conv1.weight", "model.backbone.body.layer1.0.bn1.weight", "model.backbone.body.layer1.0.bn1.bias", "model.backbone.body.layer1.0.bn1.running_mean", "model.backbone.body.layer1.0.bn1.running_var", "model.backbone.body.layer1.0.conv2.weight", "model.backbone.body.layer1.0.bn2.weight", "model.backbone.body.layer1.0.bn2.bias", "model.backbone.body.layer1.0.bn2.running_mean", "model.backbone.body.layer1.0.bn2.running_var", "model.backbone.body.layer1.0.conv3.weight", "model.backbone.body.layer1.0.bn3.weight", "model.backbone.body.layer1.0.bn3.bias", "model.backbone.body.layer1.0.bn3.running_mean", "model.backbone.body.layer1.0.bn3.running_var", "model.backbone.body.layer1.0.downsample.0.weight", "model.backbone.body.layer1.0.downsample.1.weight", "model.backbone.body.layer1.0.downsample.1.bias", "model.backbone.body.layer1.0.downsample.1.running_mean", "model.backbone.body.layer1.0.downsample.1.running_var", "model.backbone.body.layer1.1.conv1.weight", "model.backbone.body.layer1.1.bn1.weight", "model.backbone.body.layer1.1.bn1.bias", "model.backbone.body.layer1.1.bn1.running_mean", "model.backbone.body.layer1.1.bn1.running_var", "model.backbone.body.layer1.1.conv2.weight", "model.backbone.body.layer1.1.bn2.weight", "model.backbone.body.lay... Unexpected key(s) in state_dict: "faster_rcnn.backbone.body.conv1.weight", "faster_rcnn.backbone.body.conv1.bias", "faster_rcnn.backbone.body.conv1.scale", "faster_rcnn.backbone.body.conv1.zero_point", "faster_rcnn.backbone.body.bn1.weight", "faster_rcnn.backbone.body.bn1.bias", "faster_rcnn.backbone.body.bn1.running_mean", "faster_rcnn.backbone.body.bn1.running_var", "faster_rcnn.backbone.body.layer1.0.conv1.weight", "faster_rcnn.backbone.body.layer1.0.conv1.bias", "faster_rcnn.backbone.body.layer1.0.conv1.scale", "faster_rcnn.backbone.body.layer1.0.conv1.zero_point", "faster_rcnn.backbone.body.layer1.0.bn1.weight", "faster_rcnn.backbone.body.layer1.0.bn1.bias", "faster_rcnn.backbone.body.layer1.0.bn1.running_mean", "faster_rcnn.backbone.body.layer1.0.bn1.running_var", "faster_rcnn.backbone.body.layer1.0.conv2.weight", "faster_rcnn.backbone.body.layer1.0.conv2.bias", "faster_rcnn.backbone.body.layer1.0.conv2.scale", "faster_rcnn.backbone.body.layer1.0.conv2.zero_point", "faster_rcnn.backbone.body.layer1.0.bn2.weight", "faster_rcnn.backbone.body.layer1.0.bn2.bias", "faster_rcnn.backbone.body.layer1.0.bn2.running_mean", "faster_rcnn.backbone.body.layer1.0.bn2.running_var", "faster_rcnn.backbone.body.layer1.0.conv3.weight", "faster_rcnn.backbone.body.layer1.0.conv3.bias", "faster_rcnn.backbone.body.layer1.0.conv3.scale", "faster_rcnn.backbone.body.layer1.0.conv3.zero_point", "faster_rcnn.backbone.body.layer1.0.bn3.weight", "faster_rcnn.backbone.body.layer1.0.bn3.bias", "fas...

jerryzh168 commented 1 month ago

how did you get the quantized model?