SemanticSegmentationDiscreteLabels#
- class SemanticSegmentationDiscreteLabels[source]#
Bases:
SemanticSegmentationLabels
Vote-counts for each pixel belonging to each class.
Maintains a num_classes x H x W array where value_{ijk} represents how many times pixel_{jk} has been classified as class i. A label array can be obtained from this by argmax’ing along the class dimension. Can also be turned into a score converting counts to probabilities.
- __init__(extent: ~rastervision.core.box.Box, num_classes: int, dtype: ~typing.Any = <class 'numpy.uint8'>)[source]#
Constructor.
Methods
__init__
(extent, num_classes[, dtype])Constructor.
add_predictions
(windows, predictions[, crop_sz])Populate predictions.
add_window
(window, pixel_class_ids)Set labels for the given window.
filter_by_aoi
(aoi_polygons, null_class_id, ...)Keep only the values that lie inside the AOI.
from_predictions
(windows, predictions, ...)Instantiate from windows and their corresponding predictions.
get_class_mask
(window, class_id[, threshold])Get a binary mask representing all pixels of a class.
get_label_arr
(window[, null_class_id])Get labels as array of class IDs.
get_score_arr
(window)Get array of pixel scores.
get_windows
(**kwargs)Generate sliding windows over the local extent.
make_empty
(extent, num_classes)Instantiate an empty instance.
mask_fill
(window, mask, fill_value)Set fill_value'th class ID's count to 1 and all others to zero.
save
(uri, crs_transformer, class_config[, ...])Save labels as a raster and/or vectors.
- __add__(other: Self) Self [source]#
Merge self with other labels by adding the pixel counts.
- Parameters:
other (Self) –
- Return type:
Self
- __init__(extent: ~rastervision.core.box.Box, num_classes: int, dtype: ~typing.Any = <class 'numpy.uint8'>)[source]#
Constructor.
- add_predictions(windows: Iterable[Box], predictions: Iterable[Any], crop_sz: int | None = None) None #
Populate predictions.
- Parameters:
windows (Iterable[Box]) – Boxes in pixel coords, specifying chips in the raster.
predictions (Iterable[Any]) – The model predictions for each chip specified by the windows.
crop_sz (int | None) – Number of rows/columns of pixels from the edge of prediction windows to discard. This is useful because predictions near edges tend to be lower quality and can result in very visible artifacts near the edges of chips. This should only be used if the given windows represent a sliding-window grid over the scene extent with overlap between adjacent windows. Defaults to None.
- Return type:
None
- filter_by_aoi(aoi_polygons: list['Polygon'], null_class_id: int, **kwargs) Self #
Keep only the values that lie inside the AOI.
This is an inplace operation.
- Parameters:
aoi_polygons (list[Polygon]) – AOI polygons to filter by, in pixel coordinates.
null_class_id (int) – Class ID to assign to pixels falling outside the AOI polygons.
**kwargs – Extra args for
SemanticSegmentationLabels.get_windows()
.
- Return type:
Self
- classmethod from_predictions(windows: Iterable[Box], predictions: Iterable[Any], extent: Box, num_classes: int, crop_sz: int | None = None) Self [source]#
Instantiate from windows and their corresponding predictions.
- Parameters:
windows (Iterable[Box]) – Boxes in pixel coords, specifying chips in the raster.
predictions (Iterable[Any]) – The model predictions for each chip specified by the windows.
extent (Box) – The extent of the region to which the labels belong, in global coordinates.
num_classes (int) – Number of classes.
smooth – If
True
, creates aSemanticSegmentationSmoothLabels
object. IfFalse
, creates aSemanticSegmentationDiscreteLabels
object. Defaults toFalse
.crop_sz (int | None) – Number of rows/columns of pixels from the edge of prediction windows to discard. This is useful because predictions near edges tend to be lower quality and can result in very visible artifacts near the edges of chips. This should only be used if the given windows represent a sliding-window grid over the scene extent with overlap between adjacent windows. Defaults to None.
- Returns:
If smooth=True, returns a SemanticSegmentationSmoothLabels. Otherwise, a SemanticSegmentationDiscreteLabels.
- Return type:
Self
- get_class_mask(window: Box, class_id: int, threshold: float | None = None) ndarray #
Get a binary mask representing all pixels of a class.
- get_label_arr(window: Box, null_class_id: int = -1) ndarray [source]#
Get labels as array of class IDs.
Returns null_class_id for pixels for which there is no data.
- get_windows(**kwargs) list[rastervision.core.box.Box] #
Generate sliding windows over the local extent.
The keyword args are passed to
Box.get_windows()
and can therefore be used to control the specifications of the windows.If the keyword args do not contain size, a list of length 1, containing the full extent is returned.
- Parameters:
**kwargs – Extra args for
Box.get_windows()
.- Return type:
- mask_fill(window: Box, mask: ndarray, fill_value: Any) None [source]#
Set fill_value’th class ID’s count to 1 and all others to zero.
- save(uri: str, crs_transformer: CRSTransformer, class_config: ClassConfig, bbox: rastervision.core.box.Box | None = None, tmp_dir: str | None = None, save_as_rgb: bool = False, raster_output: bool = True, rasterio_block_size: int = 512, vector_outputs: Sequence[VectorOutputConfig] | None = None, profile_overrides: dict | None = None) None [source]#
Save labels as a raster and/or vectors.
If URI is remote, all files will be first written locally and then uploaded to the URI.
- Parameters:
uri (str) – URI of directory in which to save all output files.
crs_transformer (CRSTransformer) – CRSTransformer to configure CRS and affine transform of the output GeoTiff.
class_config (ClassConfig) – The ClassConfig.
bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. Must be provided if the corresponding RasterSource has
bbox != extent
.tmp_dir (str | None) – Temporary directory to use. If None, will be auto-generated. Defaults to
None
.save_as_rgb (bool) – If
True
, Saves labels as an RGB image, using the class-color mapping in the class_config. Defaults toFalse
.raster_output (bool) – If
True
, saves labels as a raster of class IDs (one band). Defaults toTrue
.rasterio_block_size (int) – Value to set blockxsize and
blockysize
to. Defaults to512
.vector_outputs (Sequence[VectorOutputConfig] | None) – List of VectorOutputConfig’s containing vectorization configuration information. Only classes for which a
VectorOutputConfig
is specified will be saved as vectors. IfNone
, no vector outputs will be produced. Defaults toNone
.profile_overrides (dict | None) – This can be used to arbitrarily override properties in the profile used to create the output GeoTiff. Defaults to
None
.
- Return type:
None