I am trying to build a MaskRCNN model with MobileNetv2 backbone using mobilenet_backbone() function.
Here is my code:
from torchvision.models.detection import MaskRCNN
from torchvision.models.detection.backbone_utils import mobilenet_backbone
 backbone = backbone_utils.mobilenet_backbone(
        backbone_name=backbone_name,
        pretrained=True,
        fpn=True)

model = MaskRCNN(backbone, num_classes)

Printed model architecture:
## skip the backbone
    (fpn): FeaturePyramidNetwork(                                                                          
      (inner_blocks): ModuleList(                                                                          
        (0): Conv2d(96, 256, kernel_size=(1, 1), stride=(1, 1))                                            
        (1): Conv2d(576, 256, kernel_size=(1, 1), stride=(1, 1))                                           
      )                                                                                                    
      (layer_blocks): ModuleList(                                                                          
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))                           
        (1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))                           
      )                                                                                                    
      (extra_blocks): LastLevelMaxPool()                                                                   
    )                                                                                                      
  )
  (rpn): RegionProposalNetwork(                                                                            
    (anchor_generator): AnchorGenerator()                                                                  
    (head): RPNHead(                                                                                       
      (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))                          
      (cls_logits): Conv2d(256, 3, kernel_size=(1, 1), stride=(1, 1))                                      
      (bbox_pred): Conv2d(256, 12, kernel_size=(1, 1), stride=(1, 1))                                      
    )                                                                                                      
  )                                                                                                        
  (roi_heads): RoIHeads(                                                                                   
    (box_roi_pool): MultiScaleRoIAlign()                                                                   
    (box_head): TwoMLPHead(                                                                                
      (fc6): Linear(in_features=12544, out_features=1024, bias=True)                                       
      (fc7): Linear(in_features=1024, out_features=1024, bias=True)                                        
    )
    (box_predictor): FastRCNNPredictor(
      (cls_score): Linear(in_features=1024, out_features=2, bias=True)
      (bbox_pred): Linear(in_features=1024, out_features=8, bias=True)
    )
    (mask_roi_pool): MultiScaleRoIAlign()
    (mask_head): MaskRCNNHeads(
      (mask_fcn1): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (relu1): ReLU(inplace=True)
      (mask_fcn2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (relu2): ReLU(inplace=True)
      (mask_fcn3): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (relu3): ReLU(inplace=True)
      (mask_fcn4): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (relu4): ReLU(inplace=True)
    )
    (mask_predictor): MaskRCNNPredictor(
      (conv5_mask): ConvTranspose2d(256, 256, kernel_size=(2, 2), stride=(2, 2))
      (relu): ReLU(inplace=True)
      (mask_fcn_logits): Conv2d(256, 2, kernel_size=(1, 1), stride=(1, 1))
    )
  )
)

But now when I try to do a forward call, I get the following error:
model.eval()
x = torch.randn(3, 128, 128)
model([x])

~/miniconda3/envs/torch-detect/lib/python3.8/site-packages/torchvision/models/detection/anchor_utils.py in grid_anchors(self, grid_sizes, strides)
    101 
    102         if not (len(grid_sizes) == len(strides) == len(cell_anchors)):
--> 103             raise ValueError("Anchors should be Tuple[Tuple[int]] because each feature "
    104                              "map could potentially have different sizes and aspect ratios. "
    105                              "There needs to be a match between the number of "

ValueError: Anchors should be Tuple[Tuple[int]] because each feature map could potentially have different sizes and aspect ratios. There needs to be a match between the number of feature maps passed and the number of sizes / aspect ratios specified.