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_label_arr
(window[, null_class_id])Get labels as array of class IDs.
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.
- add_predictions(windows: Iterable[Box], predictions: Iterable[Any], crop_sz: Optional[int] = 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 (Optional[int]) – 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[Box] [source]#
Set labels for the given window.
- filter_by_aoi(aoi_polygons: list, null_class_id: int, **kwargs) SemanticSegmentationLabels [source]#
Keep only the values that lie inside the AOI.
- Parameters
- Return type
- classmethod from_predictions(windows: Iterable[Box], predictions: Iterable[Any], extent: Box, num_classes: int, smooth: bool = False, crop_sz: Optional[int] = None) Union[SemanticSegmentationDiscreteLabels, SemanticSegmentationSmoothLabels] [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.
crop_sz (Optional[int]) – 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.
smooth (bool) –
- Returns
Union[SemanticSegmentationDiscreteLabels, SemanticSegmentationSmoothLabels]: If smooth=True, returns a
SemanticSegmentationSmoothLabels. Otherwise, a SemanticSegmentationDiscreteLabels.
- Return type
Union[SemanticSegmentationDiscreteLabels, SemanticSegmentationSmoothLabels]
- abstract get_label_arr(window: Box, null_class_id: int = -1) ndarray [source]#
Get labels as array of class IDs.
Note: The returned array is not guaranteed to be the same size as the input window.
- get_windows(**kwargs) List[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.
- classmethod make_empty(extent: Box, num_classes: int, smooth: bool = False) Union[SemanticSegmentationDiscreteLabels, SemanticSegmentationSmoothLabels] [source]#
Instantiate an empty instance.
- Parameters
- Returns
Union[SemanticSegmentationDiscreteLabels, SemanticSegmentationSmoothLabels]: If smooth=True, returns a
SemanticSegmentationSmoothLabels. Otherwise, a SemanticSegmentationDiscreteLabels.
- Raises
ValueError – if num_classes and extent are not specified, but smooth=True.
- Return type
Union[SemanticSegmentationDiscreteLabels, SemanticSegmentationSmoothLabels]