Efficient way to relabel masks?

Hi all,

Is there an efficient way to change the values of my pixel mask from 0 and 2 to 0 and 1 to allow for the unet learner? I’ve got a large dataset I want to use but they are all labeled as 0 and 2.



I would read it into np arrays and do e.g. a[np.argwhere(a == 2)] = 1. (np.place works too). run this in as many threads as your machine has with joblib Parallel and save numpy arrays back to images… (I did something similar recently and it only took me a few minutes on around 10k 256x256 masks)

Just use this:

Hope it helps :slight_smile:

1 Like