Can i extract features from Mask RCNN?

if I need to extract features using Pytorch from images by removing the last layer like in the VGG model but with the MASKRCNN model can I do that ? or it is just for object detection

It’s sometimes easier to replace the last layer with an nn.Identity module instead of trying to remove it in order to get the penultimate activations. I don’t know which layer you would like to remove, but this workflow might also work for you.

Thanks a lot for replying but excuse me i tried to print the model using this code but didn’t work

class Identity(nn.Module):
    def __init__(self):

    def forward(self, x):
        return x
PATH = 'mask_rcnn_coco.h5'
model = modellib.MaskRCNN(    )

the structure of MAskRcNN is

i need to nn.Identity the classification layer to get the features that help in classify but don’t need to classify it :slight_smile:

print(model) should print out all the initialized submodules in their order. If you want to check the implementation you would have to check the source of modellib.MaskRCNN and probably the forward implementation to see which layer to replace.

1 Like