How can I disable GeneralizedRCNNTransform from MaskRCNN torchvision model?

Torchvision has a MaskRCNN mode, when you look in the layers it has a layer called GeneralizedRCNNTransform.

I would like to remove it. Is it a good idea? How can i achieve that?

MaskRCNN doesn’t seem to use it, but FasterRCNN?
You could disable it by writing a custom class, deriving from FasterRCNN and removing this line of code.
However, note that this class just normalizes and reshapes the data as seen here.
It might be thus easier to set the mean as zeros and the std as ones to disable the normalization.

However, I would like to use the pretrained weights for resnet50.

@ptrblck Is there any way of slicing the network after having loaded the wieghts?

MaskRCNN uses a pretrained renset50 as its backbone, no?
The docs to maskrcnn_fpn_resnet50 show that a resnet is used internally.

Yes, I know.

However, when Pretrained=True, weights for all layers gets downloaded not just the ones from resnet50.

I am facing the same issue, I want to disable it altogether because I’m working with single channel images and the transformation gives me 3 channel images even when my input is explicitly given as single channel (model architecture changed prior to that as well). Is there a way to do this without losing the pretrained weights?

For anyone interested I’ve found a workaround taken from this answer here http://5.9.10.113/64957944/error-when-trying-to-train-fasterrcnn-with-custom-backbone-on-grayscale-images

Basically, we need to redefine the GeneralizedRCNNTransform and attach it to your model

grcnn = torchvision.models.detection.transform.GeneralizedRCNNTransform(min_size=800, max_size=1333, image_mean=[0.485], image_std=[0.229])
model.transform = grcnn
model.to(device)
1 Like