Instance segmentation

Such error is related to pickling. Usually pickling error happens when it feels confused on the class that you are trying to dump. (e.g. you import a class, make a change on it, and then dump an instance of the class/ your class has a conflicting name).

My best guess is that the error comes from name conflict of your data class MaskRCNN.

I see you import Mask RCNN module from torchvision (i.e. from torchvision.models.detection.mask_rcnn import *). In this module, there is also another class called MaskRCNN (see the source code), which in name conflict with your data class MaskRCNN.

Try changing the class name to something else and see if the error goes away

1 Like

Thank you very much. It solved the issue.

MaskRCNN is working now in FastAI2! :smiley:

The remaining work is:

  • Adjust the input for the metrics
  • Solve issues with FP16. Some losses of the model are NaN in FP16 and not in FP32.
  • Improve show_result

For the metrics I was given some intuition:

However, I don’t understand.


You need to write a function that passed your yb["mask"] to the metric function (in fastai) you want to use.

1 Like

Ahhh, okey. Could you link me the default function , please? So I can look at his code and override it.

I don’t know which functions should I redefine. Don’t know which line of code is calling metrics computation.

In that case all fastai metrics would work.

@sgugger I am editing this post with a better explanation.

Learner class can receive as parameter an array of metrics. Somewhere in FastAI lib should be a function that pass the data to each metric (self.yb and self.preds). I have been looking for this code inside and in callbacks.

However, I didn’t manage to find it. Could you post here the function or a link that points there, please?

I discover what you were refering for.

I have seen 2 options for solve this issue:

  • Create differents metrics that get the mask from the dict. However, It will suppose duplicating code in each class.
  • Overriding Recorder.after_batch in line 417 for met in mets: met.accumulate(self.learn). Then no need to code cuplication

Do you think that is a better option to pass a deep_copy of self.learn or other object where pred and yb contains just the masks?

Which option looks better for you?

Thank you very much for the previous help! :smiley:

I don’t understand. Could you explain it a little more please?

Hi @WaterKnight do you have any github repo of your work that is sharable ? seems very interesting.

Hey,I am training MaskRCNN right now for binary segmentation. It is fully working with variable batch size. The only thing not working is Mixed Precission It is owed to an error on PyTorch

I’ll be sharing the repo in a month! This is my final degree project.


no worries – best of luck!

I hope that by the time PyTorch solves the problem with torch.cuda.amp.autocast and maskrcnn.

In this repo you will find semantic segmentation models too!

1 Like

I guess what i am interested to see if you ficgured out a way to use an error metric. Also, does lr_finder work well for MaskRCNN

Yes, I managed to get Dice, Jaccard Coeff and other metrics for segmentation. Lr_find is working. Frezzeing and unfreezing too.

Just the only issue is Mixed Precission.

1 Like

cool – so the code snippet you pasted above actually works ? Like if we just change the name of the data class MaskRCNN, as mentioned in the comments – it will actually work – or are there other changes.
Thanks for your inputs :slight_smile:

I needed to create a new TfdmList and some new transforms

I see, so adding to the aug_transforms in the maskrccnnDataBlock ?

@pinaki f you mean Augmentation transforms, I am using the ones from Albumentations library!

Hello. Wanted to know if you managed to advance on the MaskRCNN implementation.

1 Like

Yes, Mask-RCNN is working. However as is my final degree project I can’t publish it yet :sob:


Very keen to see this too, when you’re able to publish it

@WaterKnight this is a fascinating post. Are you now able to publish your project? I’d love to take a look. Thanks!