I'm preparing data for an image segmentation model. I have 5 classes per pixel that do not cumulatively cover the entire image so I want to create a 'null' class as the 6th class. Right now I have a one-hot encoded ndarray and a solution that makes a bunch of Python calls that I am looking to optimize. My sketch code right now:
arrs.shape
(25, 25, 5)
null_class = np.zeros(arrs.shape[:-1])
for i in range(arrs.shape[0]):
for j in range(arrs.shape[1]):
if not np.any(arrs[i][j] == 1):
null_class[i][j] = 1
Ideally, I find a few-line and much more performant way of computing the null examples - my actual training data comes in 20K x 20K images and I'd like to compute and store all at once. Any advice?