r/pytorch • • Jul 09 '21

MaskRCNN postprocessing doesn't seem to fit code in git

Hey folks,

I'm currently trying to "hack" a MaskRCNN so that I get the full label distributions into the output.

I was looking into the "postprocessing_detections" function defined in roi_heads - however, when I tried to replace it with my own and slightly altered version by copying it from the git and adding minor changes, it turns out that the function seems to work different than what I find on the git.

Most importantly, it doesn't get 4 inputs - as the code in the git needs - but only 3, which seem to be head outputs, anchors and image shapes. I've found two other definitions of a function with the same name in completely different contexts (RetinaNet and SSD) which take 3 inputs; But it makes 0 sense why they'd play any role here, and also they'd want the arguments to be different types than what I get (those functions want dict, list list; MaskRCNN internally I get inputs torch.Tensor, list, list).

Does anyone have an idea how and why the methods seem to differ from what I find in the git? I literally can't find a code version that seems to fit what the MaskRCNN actuall does internally.

If it's important, here's the scheme of how I get to the model (and the error):

import torchvision
model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True)

def postprocess_detections_new(self,
                               class_logits,    # type: Tensor
                               box_regression,  # type: Tensor
                               proposals,       # type: List[Tensor]
                               image_shapes     # type: List[Tuple[int, int]]
                               ):
    --- code 1:1 copypasted from the postprocess_detections function in git ---


model.roi_heads.postprocess_detections = postprocess_detections_new

output = model(example_input)

Where example_input is some random example image I put in that works perfectly well with the unaltered model. Doing only the insertion of the copypasted code, the model already doesn't work anymore due to mismatching number of expected/given arguments.

Thanks a lot in advance, would really appreciate if somebody could point me somewhere!

0 Upvotes

2 comments sorted by

1

u/hp2304 Jul 10 '21

Version you have could be different torchvision from the one you are looking at in git. Better look for this same file in your machine (In site-packages).

1

u/TheGreatHomer Jul 10 '21

Thanks for the hint, good starting point that I didn't think about. I'm working on a colab notebook at the moment, so it doesn't work straight away. However, I pip installed the exact same version there and locally (to view the exact file), and the contradiction is still here... it must be using something else or overwrite somewhere that I can't find.