I'm trying to train an image segmentation model on satellite images. There are two main issues: first, not all of the images are the same size. My understanding is that by using a fully convolutional neural network, I can feed in images of any size, so this should not be an issue. The second problem is that the images are not rectangular. They are stored as rectangular arrays, but there are nodata values within the arrays to fill in the gaps. For example, one of the images looks like this:
Ideally, I'd like the model to ignore any nodata pixels, producing an image with the exact same shape as the input image. I have two ideas on how to accomplish this, but I feel like there is probably a better way:
- Include a "nodata" class in the training labels and teach the model to output nodata pixels if there are nodata pixels in the input. I don't like this because it requires the model to learn another class and will affect the training.
- Feed the satellite image to the model in windows, skipping any windows that contain nodata pixels. This isn't ideal either because it would mean information is lost at the edges of the windows and would probably require a lot more memory.
I see that Keras has a Masking layer, but it appears that this is intended for LSTM type models, not images. Would this work with a CNN? Or, is there a better way to solve this problem that I've missed so far?