I noticed that the MaskBlock also contains an IntToFloatTensor batch transformation and I wonder why it is there. Batch transforms are not applied to label masks if you build a U-Net learner with fastai (after all you want the masks as int tensors). Is this a bug or am I missing something?
def MaskBlock(codes=None):
"A `TransformBlock` for segmentation masks, potentially with `codes`"
return TransformBlock(type_tfms=PILMask.create, item_tfms=AddMaskCodes(codes=codes), **batch_tfms=IntToFloatTensor**)
Just found the need for using the batch_tfms with masks. If your masks are binary with two classes say background and foreground denoted by pixel values of 0 and 255, you will need to change masks to only contain 0 and 1 for pixel values denoting the segmentation classes. Transforms like IntToFloatTensor for masks are life savers. All you need to do is to add IntToFloatTensor(div_mask=255) to your batch_tfms and you are all set. One use case for performing batch transformation on masks.