GriddedPatchSampler#

../../_images/GriddedPatchSampler.gif
class torchgeo.samplers.GriddedPatchSampler(dataset, *, size, stride=None, roi=None, units=Units.PIXELS)[source]#

Bases: SpatialSampler

Sample locations from a region of interest in a grid-like fashion.

This is particularly useful during evaluation when you want to make predictions for an entire region of interest. You want to minimize the amount of redundant computation by minimizing overlap between chips.

Usually the stride should be slightly smaller than the chip size such that each chip has some small overlap with surrounding chips. This is used to prevent stitching artifacts when combining each prediction patch. The overlap between each chip (size - stride) should be approximately equal to the receptive field of the CNN.

Added in version 0.10.

__init__(dataset, *, size, stride=None, roi=None, units=Units.PIXELS)[source]#

Initialize a new GriddedPatchSampler instance.

The size and stride arguments can either be:

  • a single float - in which case the same value is used for the height and width dimension

  • a tuple of two floats - in which case, the first float is used for the height dimension, and the second float for the width dimension

Parameters:
  • dataset (GeoDataset) – Dataset to sample from.

  • size (tuple[float, float] | float) – Dimensions of each patch.

  • stride (tuple[float, float] | float | None) – Distance to skip between each patch (defaults to size).

  • roi (Polygon | None) – Region of interest to sample from (defaults to the bounds of dataset.index).

  • units (Units) – Defines if size and stride are in pixel or CRS units.

__iter__()[source]#

Iterate over generated sample locations for each epoch.

Yields:

[xmin – xmax, ymin:ymax] coordinates to index a dataset.