I am trying to change the RESNET50 backbone of Faster RCNN by MobileNET.
My code seems like:
from torchvision.models.detection import FasterRCNN
backbone = torchvision.models.mobilenet_v2(pretrained=True)
backbone.out_channels = 1280
model = FasterRCNN(backbone)
But i get this error
ValueError: num_classes should not be None when box_predictor is not specified
I am starting with this kind of networks, so there are many things that i am still learning, any help would be great.
The objective that i have is to compare the time inference of resnet 50+faster (default) vs mobilenet+faster, so i dont want either train or fine tuning the network
def fasterrcnn_resnet50_fpn(pretrained=False, progress=True,
num_classes=91, pretrained_backbone=True, **kwargs):
if pretrained:
pretrained_backbone = False
backbone = resnet_fpn_backbone('resnet50', pretrained_backbone)
model = FasterRCNN(backbone, num_classes, **kwargs)
if pretrained:
state_dict = load_state_dict_from_url(model_urls['fasterrcnn_resnet50_fpn_coco'],
progress=progress)
model.load_state_dict(state_dict)
return model
# FasterRCNN __init__ function
if num_classes is not None:
if box_predictor is not None:
raise ValueError("num_classes should be None when box_predictor is specified")
else:
if box_predictor is None:
raise ValueError("num_classes should not be None when box_predictor "
"is not specified")