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 – 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 toNone
.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 to100
.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 toTrue
.to_pytorch – If
True
, the sampled chips and labels are converted to pytorch tensors. Defaults toTrue
.return_window – Make
__getitem__
return the window coordinates used to generate the image. Defaults toFalse
.
Methods
__init__
(*args, **kwargs)Constructor.
append_resize_transform
(transform, out_size)Get transform to use for resizing windows to out_size.
from_uris
(image_uri[, label_vector_uri, ...])Create an instance of this class from image and label URIs.
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.
Randomly sample the window size.
- __add__(other: Dataset[T_co]) ConcatDataset[T_co] #
- Parameters:
other (Dataset[T_co]) –
- Return type:
ConcatDataset[T_co]
- __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 toNone
.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 to100
.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 toTrue
.to_pytorch – If
True
, the sampled chips and labels are converted to pytorch tensors. Defaults toTrue
.return_window – Make
__getitem__
return the window coordinates used to generate the image. Defaults toFalse
.
- 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.
- classmethod from_uris(image_uri: str | list[str], label_vector_uri: str | None = None, class_config: ClassConfig | None = None, aoi_uri: str | list[str] = [], label_vector_default_class_id: int | None = 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 (ClassConfig | None) – The
ClassConfig
.image_uri (str | list[str]) – URI or list of URIs of GeoTIFFs to use as the source of image data.
label_vector_uri (str | None) – URI of GeoJSON file to use as the source of segmentation label data. Defaults to
None
.class_config – The
ClassConfig
. Can beNone
if not using any labels.aoi_uri (str | list[str]) – 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 (int | None) – 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 forClassInferenceTransformer
for more details. Defaults toNone
.image_raster_source_kw (dict) – 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) – Additional arguments to pass to the
GeoJSONVectorSourceConfig
used for label data, iflabel_vector_uri
is set. See docs forGeoJSONVectorSourceConfig
for more details. Defaults to{}
.label_source_kw (dict) – Additional arguments to pass to the
ChipClassificationLabelSourceConfig
used for label data, iflabel_vector_uri
is set. See docs forChipClassificationLabelSourceConfig
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.
- 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:
- sample_window_loc(h: int, w: int) tuple[int, int] #
Randomly sample coordinates of the top left corner of the window.
- property max_size#
- property min_size#