Answers.Body: <p>I'm running into the same issue. Zero padding is common in the machine learning world to deal with conforming to the architecture dimensions, so I suppose changing nodata values to 0's and feeding that into the model could be a potential solution, though I'm concerned the model would learn to just ignore that part of the image in every image it sees. Not a problem if that pattern of nodata is consistent with all your images, but that's rarely the case with remotely sensed data. Have you figured out another solution since posting this?</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-04T00:23:02.397Z
Answers.Text: Hi, welcome to the forum! This seems to better fit as a comment on original question, rather than an answer.
Answers.UserDisplayName: Alexander Wan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-05T01:02:20.963Z
Answers.Text: I agree, but I'm not allowed to comment yet. ¯\_(ツ)_/¯
Answers.UserDisplayName: user5819638
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-28T23:01:27.193Z
Answers.LastActivityDate: 2023-08-28T23:01:27.193Z
Answers.UserDisplayName: user5819638
Body: <p>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:
  <a href="https://i.sstatic.net/2HIwU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2HIwU.png" alt="A non-rectangular satellite image." /></a></p>
  <p>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:</p>
  <ol>
  <li>Include a &quot;nodata&quot; 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.</li>
  <li>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.</li>
  </ol>
  <p>I see that Keras has a <a href="https://keras.io/api/layers/core_layers/masking/" rel="nofollow noreferrer">Masking</a> 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?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-11-30T09:05:17.810Z
Comments.Text: have you solved it? Is it better to make it a separate category to solve this error?
Comments.UserDisplayName: huateng ma
Tags: <convolutional-neural-networks><keras><image-segmentation>
Title: How can I tell a CNN to ignore nodata values in satellite images?
UserDisplayName: gnarw0lf
ThreadText: # How can I tell a CNN to ignore nodata values in satellite images?
  
  (Asked by: username_0 on 2023-04-24)
  
  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:
  [![A non-rectangular satellite image.](https://i.sstatic.net/2HIwU.png)](https://i.sstatic.net/2HIwU.png)
  
  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:
  
  1. 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.
  2. 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](https://keras.io/api/layers/core_layers/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?
  
  **Tags:** convolutional-neural-networks, keras, image-segmentation
  
  > **Comments:**
  > **username_1**: have you solved it? Is it better to make it a separate category to solve this error?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2023-08-28. Score: 1
  
  I'm running into the same issue. Zero padding is common in the machine learning world to deal with conforming to the architecture dimensions, so I suppose changing nodata values to 0's and feeding that into the model could be a potential solution, though I'm concerned the model would learn to just ignore that part of the image in every image it sees. Not a problem if that pattern of nodata is consistent with all your images, but that's rarely the case with remotely sensed data. Have you figured out another solution since posting this?
  
  > **Comments:**
  > **username_3**: Hi, welcome to the forum! This seems to better fit as a comment on original question, rather than an answer.  
  > **username_2**: I agree, but I'm not allowed to comment yet. ¯\_(ツ)_/¯  
  
  ---
  
  