when i run the official tutorial–TORCHVISION OBJECT DETECTION FINETUNING TUTORIAL , i got a error : AttributeError: ‘FastRCNNPredictor’ object has no attribute ‘conv5_mask’
It was successful on the colab but failed to run locally
emcp
(emcp)
May 6, 2020, 9:54am
5
you likely need to share your local code in order to debug… do you have a link to a git repo?
ok ,this is the code . i run it on win10 , pycharm.
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'))))
This file has been truncated. show original
emcp
(emcp)
May 6, 2020, 12:50pm
7
def get_instance_segmentation_model(num_classes):
# load an instance segmentation model pre-trained on COCO
model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)
# get the mumber of input features of 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.box_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
def get_transform(train):
transforms = []
# convert the image, a PIL image, into a PyTorch Tensor
line 91 should be mask predictor … not box predictor
look at the tutorial again
# 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