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 (Scene) – A Scene object.

  • out_size (Optional[Union[PosInt, Tuple[PosInt, PosInt]]]]) – 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 (Optional[Tuple[PosInt, PosInt]]) – Interval from which to sample window size.

  • h_lims (Optional[Tuple[PosInt, PosInt]]) – Interval from which to sample window height.

  • w_lims (Optional[Tuple[PosInt, PosInt]]) – Interval from which to sample window width.

  • padding (Optional[Union[NonNegInt, Tuple[NonNegInt, NonNegInt]]]) – How many pixels the windows are allowed to overflow the sides of the raster source. If None, padding = size. Defaults to None.

  • max_windows (Optional[NonNegInt]) – Max allowed reads. Will raise StopIteration on further read attempts. If None, will be set to np.inf. Defaults to None.

  • transform (Optional[A.BasicTransform], optional) – 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 (Optional[TransformType], optional) – Type of transform. Defaults to None.

  • max_sample_attempts (NonNegInt, optional) – 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 (bool, optional) – 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.

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

  • transform_type – Type of transform. Defaults to None.

  • normalize (bool, optional) – If True, x is normalized to [0, 1] based on its data type. Defaults to True.

  • to_pytorch (bool, optional) – If True, x and y are converted to pytorch tensors. Defaults to True.

  • return_window (bool, optional) – Make __getitem__ return the window coordinates used to generate the image. Defaults to False.

Methods

__init__(*args, **kwargs)

Constructor.

from_uris(*args, **kwargs)

get_resize_transform(transform, out_size)

Get transform to use for resizing windows to out_size.

sample_window()

If scene has AOI polygons, try to find a random window that is 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.

__contains__(key: str) bool#
Parameters

key (str) –

Return type

bool

__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 (Scene) – A Scene object.

  • out_size (Optional[Union[PosInt, Tuple[PosInt, PosInt]]]]) – 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 (Optional[Tuple[PosInt, PosInt]]) – Interval from which to sample window size.

  • h_lims (Optional[Tuple[PosInt, PosInt]]) – Interval from which to sample window height.

  • w_lims (Optional[Tuple[PosInt, PosInt]]) – Interval from which to sample window width.

  • padding (Optional[Union[NonNegInt, Tuple[NonNegInt, NonNegInt]]]) – How many pixels the windows are allowed to overflow the sides of the raster source. If None, padding = size. Defaults to None.

  • max_windows (Optional[NonNegInt]) – Max allowed reads. Will raise StopIteration on further read attempts. If None, will be set to np.inf. Defaults to None.

  • transform (Optional[A.BasicTransform], optional) – 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 (Optional[TransformType], optional) – Type of transform. Defaults to None.

  • max_sample_attempts (NonNegInt, optional) – 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 (bool, optional) – 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.

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

  • transform_type – Type of transform. Defaults to None.

  • normalize (bool, optional) – If True, x is normalized to [0, 1] based on its data type. Defaults to True.

  • to_pytorch (bool, optional) – If True, x and y are converted to pytorch tensors. Defaults to True.

  • return_window (bool, optional) – Make __getitem__ return the window coordinates used to generate the image. Defaults to False.

static __new__(cls, *args: Any, **kwargs: Any) Any#
Parameters
  • args (Any) –

  • kwargs (Any) –

Return type

Any

classmethod from_uris(*args, **kwargs) GeoDataset#
Return type

GeoDataset

get_resize_transform(transform: Optional[BasicTransform], out_size: Tuple[PositiveInt, PositiveInt]) Union[Resize, Compose]#

Get transform to use for resizing windows to out_size.

Parameters
  • transform (Optional[BasicTransform]) –

  • out_size (Tuple[PositiveInt, PositiveInt]) –

Return type

Union[Resize, Compose]

sample_window() Box#

If 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#