RandomPatchSampler#
- class torchgeo.samplers.RandomPatchSampler(dataset, *, size, length=None, roi=None, units=Units.PIXELS, generator=None)[source]#
Bases:
SpatialSamplerSample locations from a region of interest randomly.
This is particularly useful during training when you want to maximize the size of the dataset and return as many random chips as possible. Note that randomly sampled chips may overlap.
Added in version 0.10.
- __init__(dataset, *, size, length=None, roi=None, units=Units.PIXELS, generator=None)[source]#
Initialize a new RandomPatchSampler instance.
The
sizeargument can either be:a single
float- in which case the same value is used for the height and width dimensiona
tupleof 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.
length (int | None) – Number of random samples to draw per epoch (defaults to approximately the maximal number of non-overlapping chips of size
sizethat could be sampled from the dataset).roi (Polygon | None) – Region of interest to sample from (defaults to the bounds of
dataset.index).units (Units) – Defines if
sizeis in pixel or CRS units.generator (int | BitGenerator | Generator | RandomState | SeedSequence | None) – Pseudo-random number generator (PRNG).