MASKRCNN, Error while loading the model

Vijay_Deshpande: <p> in get_instance_segmentation_model(num_classes)<br>
24     model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True, progress=True,<br>
25                                                        num_classes=num_classes, pretrained_backbone=True,<br>
—&gt; 26                                                        trainable_backbone_layers=3)<br>
27<br>
28</p>
<p>/usr/local/lib/python3.6/site-packages/torchvision/models/detection/mask_rcnn.py in maskrcnn_resnet50_fpn(pretrained, progress, num_classes, pretrained_backbone, **kwargs)<br>
310         pretrained_backbone = False<br>
311     backbone = resnet_fpn_backbone(‘resnet50’, pretrained_backbone)<br>
–&gt; 312     model = MaskRCNN(backbone, num_classes, **kwargs)<br>
313     if pretrained:<br>
314         state_dict = load_state_dict_from_url(model_urls[‘maskrcnn_resnet50_fpn_coco’],</p>
<p>TypeError: <strong>init</strong>() got an unexpected keyword argument ‘trainable_backbone_layers’</p>

ptrblck: <p>The <code>trainable_backbone_layers</code> argument was added ~2months ago in <a href="https://github.com/pytorch/vision/pull/2242">this PR</a>, so you might need to update <code>torchvision</code>.</p>

Jake_Fleisig: <p>Hello, I just upgraded to torch 1.5.1 and torchvision 0.6.1 but I am still getting this error. my code is bellow</p>
<pre><code class="lang-auto">import torch
import torchvision
import torchvision.models.detection.mask_rcnn
from torchvision.models.detection.rpn import AnchorGenerator
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from torchvision.models.detection.mask_rcnn import MaskRCNNPredictor

print(torch.__version__)
print(torchvision.__version__)
</code></pre>
<p>1.5.1<br>
0.6.1</p>
<pre><code class="lang-auto">def get_model(num_classes, pretrained=True):
    
    # load an instance segmentation model pre-trained on COCO
    model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=pretrained, trainable_backbone_layers=5)

    # get the number of input features for the classifier
    in_features = model.roi_heads.box_predictor.cls_score.in_features
    
    # replace the pre-trained head with a new one
    model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)

    # now get the number of input features for the mask classifier
    in_features_mask = model.roi_heads.mask_predictor.conv5_mask.in_channels
    hidden_layer = 256
    
    # and replace the mask predictor with a new one
    model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask, hidden_layer, num_classes)
    return model

model = get_model(2)
</code></pre>
<hr>
<p>TypeError                                 Traceback (most recent call last)<br>
 in <br>
----&gt; 1 model = get_model(2)</p>
<p> in get_model(num_classes, pretrained)<br>
2<br>
3     # load an instance segmentation model pre-trained on COCO<br>
----&gt; 4     model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=pretrained, trainable_backbone_layers=5)<br>
5<br>
6     # get the number of input features for the classifier</p>
<p>/opt/conda/lib/python3.6/site-packages/torchvision/models/detection/mask_rcnn.py in maskrcnn_resnet50_fpn(pretrained, progress, num_classes, pretrained_backbone, **kwargs)<br>
316         pretrained_backbone = False<br>
317     backbone = resnet_fpn_backbone(‘resnet50’, pretrained_backbone)<br>
–&gt; 318     model = MaskRCNN(backbone, num_classes, **kwargs)<br>
319     if pretrained:<br>
320         state_dict = load_state_dict_from_url(model_urls[‘maskrcnn_resnet50_fpn_coco’],</p>
<p>TypeError: <strong>init</strong>() got an unexpected keyword argument ‘trainable_backbone_layers’</p>