RegressionRandomWindowGeoDataset#

class RegressionRandomWindowGeoDataset[source]#

Bases: RandomWindowGeoDataset

Attributes

__init__(*args, **kwargs)[source]#

Constructor.

Will sample square windows if size_lims is specified. Otherwise, will sample rectangular windows with height and width sampled according to h_lims and w_lims.

Parameters:
  • scene – A Scene object.

  • out_size – Resize windows to this size before returning. This is to aid in collating the windows into a batch. If None, windows are returned without being normalized or converted to pytorch, and will be of different sizes in successive reads.

  • size_lims – Interval from which to sample window size.

  • h_lims – Interval from which to sample window height.

  • w_lims – Interval from which to sample window width.

  • padding – How many pixels the windows are allowed to overflow the sides of the raster source. If None, padding = size. Defaults to None.

  • max_windows – Max allowed reads. Will raise StopIteration on further read attempts.

  • transform – Albumentations transform to apply to the windows. Defaults to None. Each transform in Albumentations takes images of type uint8, and sometimes other data types. The data type requirements can be seen at https://albumentations.ai/docs/api_reference/augmentations/transforms/ If there is a mismatch between the data type of imagery and the transform requirements, a RasterTransformer should be set on the RasterSource that converts to uint8, such as MinMaxTransformer or StatsTransformer.

  • transform_type – Type of transform. Defaults to None.

  • max_sample_attempts – Max attempts when trying to find a window within the AOI of the scene. Only used if the scene has aoi_polygons specified. StopIteratioin is raised if this is exceeded. Defaults to 100.

  • efficient_aoi_sampling – If the scene has AOIs, sampling windows at random anywhere in the extent and then checking if they fall within any of the AOIs can be very inefficient. This flag enables the use of an alternate algorithm that only samples window locations inside the AOIs. Defaults to True.

  • AOI (within_aoi If True and if the scene has an) – windows that lie fully within the AOI. If False, windows only partially intersecting the AOI will also be allowed. Defaults to True.

  • sample (only) – windows that lie fully within the AOI. If False, windows only partially intersecting the AOI will also be allowed. Defaults to True.

  • transform – Albumentations transform to apply to the windows. Defaults to None.

  • transform_type – Type of transform. Defaults to None.

  • normalize – If True, the sampled chips are normalized to [0, 1] based on their data type. Defaults to True.

  • to_pytorch – If True, the sampled chips and labels are converted to pytorch tensors. Defaults to True.

  • return_window – Make __getitem__ return the window coordinates used to generate the image. Defaults to False.

Methods

__init__(*args, **kwargs)

Constructor.

append_resize_transform(transform, out_size)

Get transform to use for resizing windows to out_size.

from_uris(*args, **kwargs)

sample_window()

Sample a window with random size and location within the AOI.

sample_window_loc(h, w)

Randomly sample coordinates of the top left corner of the window.

sample_window_size()

Randomly sample the window size.

__add__(other: Dataset[T_co]) ConcatDataset[T_co]#
Parameters:

other (Dataset[T_co]) –

Return type:

ConcatDataset[T_co]

__getitem__(idx: int)#
Parameters:

idx (int) –

__init__(*args, **kwargs)[source]#

Constructor.

Will sample square windows if size_lims is specified. Otherwise, will sample rectangular windows with height and width sampled according to h_lims and w_lims.

Parameters:
  • scene – A Scene object.

  • out_size – Resize windows to this size before returning. This is to aid in collating the windows into a batch. If None, windows are returned without being normalized or converted to pytorch, and will be of different sizes in successive reads.

  • size_lims – Interval from which to sample window size.

  • h_lims – Interval from which to sample window height.

  • w_lims – Interval from which to sample window width.

  • padding – How many pixels the windows are allowed to overflow the sides of the raster source. If None, padding = size. Defaults to None.

  • max_windows – Max allowed reads. Will raise StopIteration on further read attempts.

  • transform – Albumentations transform to apply to the windows. Defaults to None. Each transform in Albumentations takes images of type uint8, and sometimes other data types. The data type requirements can be seen at https://albumentations.ai/docs/api_reference/augmentations/transforms/ If there is a mismatch between the data type of imagery and the transform requirements, a RasterTransformer should be set on the RasterSource that converts to uint8, such as MinMaxTransformer or StatsTransformer.

  • transform_type – Type of transform. Defaults to None.

  • max_sample_attempts – Max attempts when trying to find a window within the AOI of the scene. Only used if the scene has aoi_polygons specified. StopIteratioin is raised if this is exceeded. Defaults to 100.

  • efficient_aoi_sampling – If the scene has AOIs, sampling windows at random anywhere in the extent and then checking if they fall within any of the AOIs can be very inefficient. This flag enables the use of an alternate algorithm that only samples window locations inside the AOIs. Defaults to True.

  • AOI (within_aoi If True and if the scene has an) – windows that lie fully within the AOI. If False, windows only partially intersecting the AOI will also be allowed. Defaults to True.

  • sample (only) – windows that lie fully within the AOI. If False, windows only partially intersecting the AOI will also be allowed. Defaults to True.

  • transform – Albumentations transform to apply to the windows. Defaults to None.

  • transform_type – Type of transform. Defaults to None.

  • normalize – If True, the sampled chips are normalized to [0, 1] based on their data type. Defaults to True.

  • to_pytorch – If True, the sampled chips and labels are converted to pytorch tensors. Defaults to True.

  • return_window – Make __getitem__ return the window coordinates used to generate the image. Defaults to False.

append_resize_transform(transform: albumentations.core.transforms_interface.BasicTransform | None, out_size: tuple[int, int]) albumentations.augmentations.geometric.resize.Resize | albumentations.core.composition.Compose#

Get transform to use for resizing windows to out_size.

Parameters:
  • transform (albumentations.core.transforms_interface.BasicTransform | None) –

  • out_size (tuple[int, int]) –

Return type:

albumentations.augmentations.geometric.resize.Resize | albumentations.core.composition.Compose

classmethod from_uris(*args, **kwargs) Self#
Return type:

Self

sample_window() Box#

Sample a window with random size and location within the AOI.

If the scene has AOI polygons, try to find a random window that is within the AOI. Otherwise, just return the first sampled window.

Raises:

StopIteration – If unable to find a valid window within self.max_sample_attempts attempts.

Returns:

The sampled window.

Return type:

Box

sample_window_loc(h: int, w: int) tuple[int, int]#

Randomly sample coordinates of the top left corner of the window.

Parameters:
Return type:

tuple[int, int]

sample_window_size() tuple[int, int]#

Randomly sample the window size.

Return type:

tuple[int, int]

property max_size#
property min_size#