AttributeError: 'FastRCNNPredictor' object has no attribute 'conv5_mask'

username: googlelee
cooked: <p>when i run the official tutorial–<a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html" rel="nofollow noopener">TORCHVISION OBJECT DETECTION FINETUNING TUTORIAL</a>, i got a error : AttributeError: ‘FastRCNNPredictor’ object has no attribute ‘conv5_mask’</p>

username: googlelee
cooked: <p>It was successful on the colab but failed to run locally</p>

username: emcp
cooked: <p>you likely need to share your local code in order to debug… do you have a link to a git repo?</p>

username: googlelee
cooked: <p>ok ,this is the code . i run it on win10 , pycharm.<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py" target="_blank" rel="nofollow noopener">googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py</a></h4>
<pre><code class="lang-py">import os
import numpy as np
import torch
import torch.utils.data as data
from PIL import Image
import torchvision
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
from torchvision.models.detection.mask_rcnn import MaskRCNNPredictor
from engine import train_one_epoch, evaluate
import utils
import transforms as T


class PennFudanDataset(data.Dataset):
    def __init__(self, root, transforms=None):
        self.root = root
        self.transforms = transforms
        # load all image files , sorting them to
        # ensure that they are aligned
        self.imgs = list(sorted(os.listdir(os.path.join(root, 'PNGImages'))))
</code></pre>

  This file has been truncated. <a href="https://github.com/googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py" target="_blank" rel="nofollow noopener">show original</a>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>

username: emcp
cooked: <aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py#L91" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py#L91" target="_blank" rel="nofollow noopener">googlelee/TORCHVISION-OBJECT-DETECTION-FINETUNING-TUTORIAL/blob/master/main.py#L91</a></h4>
<pre class="onebox"><code class="lang-py"><ol class="start lines" start="81" style="counter-reset: li-counter 80 ;">
<li>
</li>
<li>def get_instance_segmentation_model(num_classes):
</li>
<li>    # load an instance segmentation model pre-trained on COCO
</li>
<li>    model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)
</li>
<li>
</li>
<li>    # get the mumber of input features of the classifier
</li>
<li>    in_features = model.roi_heads.box_predictor.cls_score.in_features
</li>
<li>    # replace the pre-trained head with a new one
</li>
<li>    model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
</li>
<li>    # now get the number of input features for the mask classifier
</li>
<li class="selected">    in_features_mask = model.roi_heads.box_predictor.conv5_mask.in_channels
</li>
<li>    hidden_layer = 256
</li>
<li>    # and replace the mask predictor with a new one
</li>
<li>    model.roi_heads.mask_predictor = MaskRCNNPredictor(in_features_mask, hidden_layer, num_classes)
</li>
<li>
</li>
<li>    return model
</li>
<li>
</li>
<li>
</li>
<li>def get_transform(train):
</li>
<li>    transforms = []
</li>
<li>    # convert the image, a PIL image, into a PyTorch Tensor
</li>
</ol></code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>line 91 should be mask predictor … not box predictor</p>
<p>look at the tutorial again</p>
<pre><code class="lang-auto"> # 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
</code></pre>

username: googlelee
cooked: <p>ok, thank you , it works</p>