How do I crop a Landsat image into smaller chunks for training and then predict on the original image

Viewed 152

I am looking at using Landsat imagery to train a CNN for unsupervised pixel-wise semantic segmentation classification. That said, I have been unable to find a method that allows me to crop images from the larger Landsat image for training and then predict on the original image. Essentially here is what I am trying to do:

Original Landsat image (5,000 x 5,000 - this is an arbitrary size, not exactly sure of the actual dimensions off-hand) -> crop the image into (100 x 100) chunks -> train the model on these cropped images -> output a prediction for each pixel in the original (uncropped) image.

That said, I am not sure if I should predict on the cropped images and stitch them together after they are predicted or if I can predict on the original image.

Any clarification/code examples would be greatly appreciated. For reference, I use both pytorch and tensorflow.

Thank you! Lance D

1 Answers

Borrowing from Ronneberger et al., what we have been doing is to split the input Landsat scene and corresponding ground truth mask into overlapping tiles. Take the original image and pad it by the overlap margin (we use reflection for the padding) then split into tiles. Here is a code snippet using scikit-image:

import skimage as sk
patches = sk.util.view_as_windows(image,
  (self.tile_height+2*self.image_margin,
  self.tile_width+2*self.image_margin,raster_value['channels']),
  (self.tile_height,self.tile_width,raster_value['channels'])

I don't know what you are using for a loss function for unsupervised segmentation. In our case with supervised learning, we crop the final segmentation prediction to match the ground truth output shape. In the Ronneberger paper they relied on shrinkage due to the use of valid padding. For predictions you would do the same (split into overlapping tiles) and stitch the result.

Related