Segmentation Masks from Function (RLE)

Is anyone able to load segmentation masks computed through run-length-encoding, or some function besides reading from disk? FastAI v1 used to have this. It looks like fastai v2 only supports reading seg-masks.

I tried adapting the old RLE code to a label function, but it needs to read from a dataframe to get the encoding, it’s not obvious how to write a get_y function that’ll look at filename and a CSV. For reference, the v2 docs for high-level and datablock APIs, as well as the walk-with-fastai segmentation example all use functions that read from disk.

My first thought was maybe there’s a way to use .from_df: take ColReader and pass its output to a label function for get_y?

Or would the correct way be to create a modified from_df method?

SegmentationDataLoaders does have a .from_label_func method, but that’d require loading a CSV as dataframe for each label, so that’s out of the question. So maybe what’s needed is a combined .from_label_func / .from_df kind of method.

Why it’s important: as things are you’re potentially doubling the size of your dataset to store segmentation labels.

1 Like

To add on to this: I think you’re able to define “online” or “dynamic” preprocessing by using fastai’s transforms system. If I get that working I’ll add a walkthrough of it here and maybe a blog post. (here’s a new reply since I don’t see an option to edit the original post 2 months later).