ClassificationRandomWindowGeoDataset#

class ClassificationRandomWindowGeoDataset[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(image_uri[, label_vector_uri, ...])

Create an instance of this class from image and label URIs.

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(image_uri: Union[str, List[str]], label_vector_uri: Optional[str] = None, class_config: Optional[ClassConfig] = None, aoi_uri: Union[str, List[str]] = [], label_vector_default_class_id: Optional[int] = None, image_raster_source_kw: dict = {}, label_vector_source_kw: dict = {}, label_source_kw: dict = {}, **kwargs)#

Create an instance of this class from image and label URIs.

This is a convenience method. For more fine-grained control, it is recommended to use the default constructor.

Parameters
  • class_config (Optional['ClassConfig']) – The ClassConfig.

  • image_uri (Union[str, List[str]]) – URI or list of URIs of GeoTIFFs to use as the source of image data.

  • label_vector_uri (Optional[str], optional) – URI of GeoJSON file to use as the source of segmentation label data. Defaults to None.

  • class_config – The ClassConfig. Can be None if not using any labels.

  • aoi_uri (Union[str, List[str]], optional) – URI or list of URIs of GeoJSONs that specify the area-of-interest. If provided, the dataset will only access data from this area. Defaults to [].

  • label_vector_default_class_id (Optional[int], optional) – If using label_vector_uri and all polygons in that file belong to the same class and they do not contain a class_id property, then use this argument to map all of the polygons to the appropriate class ID. See docs for ClassInferenceTransformer for more details. Defaults to None.

  • image_raster_source_kw (dict, optional) – Additional arguments to pass to the RasterioSource used for image data. See docs for RasterioSource for more details. Defaults to {}.

  • label_vector_source_kw (dict, optional) – Additional arguments to pass to the GeoJSONVectorSourceConfig used for label data, if label_vector_uri is set. See docs for GeoJSONVectorSourceConfig for more details. Defaults to {}.

  • label_source_kw (dict, optional) – Additional arguments to pass to the ChipClassificationLabelSourceConfig used for label data, if label_vector_uri is set. See docs for ChipClassificationLabelSourceConfig for more details. Defaults to {}.

  • **kwargs – All other keyword args are passed to the default constructor for this class.

Returns

An instance of this GeoDataset subclass.

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#