SemanticSegmentationLabels#
- class SemanticSegmentationLabels[source]#
Bases:
Labels
Representation of Semantic Segmentation labels.
Methods
__init__
(extent, num_classes, dtype)Constructor.
add_predictions
(windows, predictions[, crop_sz])Populate predictions.
add_window
(window, values)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 a 2D array of class IDs.
get_score_arr
(window[, null_class_id])Get (C, H, W) array of pixel scores.
get_windows
(**kwargs)Generate sliding windows over the local extent.
make_empty
(extent, num_classes[, smooth])Instantiate an empty instance.
mask_fill
(window, mask, fill_value)Given a window and a binary mask, set all the pixels in the window for which the mask is ON to the fill_value.
save
(uri)Save to file.
- abstract __add__(other: Self) Self [source]#
Merge self with other labels.
- Parameters
other (Self) –
- Return type
Self
- add_predictions(windows: Iterable[Box], predictions: Iterable[Any], crop_sz: int | None = None) None [source]#
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
- abstract add_window(window: Box, values: ndarray) list[rastervision.core.box.Box] [source]#
Set labels for the given window.
- Parameters
- Return type
- filter_by_aoi(aoi_polygons: list['Polygon'], null_class_id: int, **kwargs) Self [source]#
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, smooth: bool = False, 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 (bool) – 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 [source]#
Get a binary mask representing all pixels of a class.
- abstract get_label_arr(window: Box, null_class_id: int = -1) ndarray [source]#
Get labels as a 2D array of class IDs.
Note: The returned array is not guaranteed to be the same size as the input window.
- abstract get_score_arr(window: Box, null_class_id: int = -1) ndarray [source]#
Get (C, H, W) array of pixel scores.
- get_windows(**kwargs) list[rastervision.core.box.Box] [source]#
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
- classmethod make_empty(extent: Box, num_classes: int, smooth: bool = False) Self [source]#
Instantiate an empty instance.
- Parameters
- Returns
If smooth=True, returns a SemanticSegmentationSmoothLabels. Otherwise, a SemanticSegmentationDiscreteLabels.
- Raises
ValueError – if num_classes and extent are not specified, but smooth=True.
- Return type
Self