Custom FasterRCNN

Hey everyone.

I’m trying to modify fasterrcnn_mobilenet_v3_large_320_fpn to train it on a custom 5 classes dataset. The problem is I’m having issues using this modified model.

This raises the error: TypeError: forward() takes 2 positional arguments but 3 were given

I have read that this is not a sequential model, so maybe that’s why this approach is not working, but I’m still wondering how should I approach this issue. I’m just interested in getting the pretrained model, adapting it to 5 classes and training it. What would be the easiest way to do so? Could you provide me some insights and/or reading material?

Thanks in advance.

I think the easier approach would be to specify the num_classes during the model instantiation and to use a pretrained backbone if needed:

model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_320_fpn(
    pretrained=False, num_classes=5, pretrained_backbone=True)
1 Like

That is true, it solved for me. Thanks for helping out, as always.