How to change MaskRCNN loss function?

I’m using PyTorch’s MaskRCNN implementation. I want to change the loss function to something custom. I tried using this:

model = maskrcnn_resnet50_fpn(weights=MaskRCNN_ResNet50_FPN_Weights.DEFAULT)
model.roi_heads.maskrcnn_loss = my_loss

But this doesn’t seem to work. When I include a print statement in my_loss it never gets called.

Does anyone know how to fix this?

Fixed it. Instead of:

model.roi_heads.maskrcnn_loss = my_loss

I needed to use:

roi_heads.maskrcnn_loss = my_loss
1 Like