How to load polygon mask data from .txt file for Image segmentation using UNET

You need some code that rasterises the coordinates - that is, turns the polygons into a numpy array. If you haven’t been provided code with the data, there are plenty of algorithms on stack overflow etc.

You then have the choice of 1) saving the mask arrays as png’s, which fastai can read natively. Or 2) writing a function that turns polygon coordinates into arrays on the fly as images are read during training. Look at open_mask_rle in the code to see a similar example. I prefer to do (1) as I hate re-computing anything. But sometimes file saving constraints mean (2) is better or you just find it more elegant. Good luck!

1 Like