SemanticSegmentationLabelStore#

class SemanticSegmentationLabelStore[source]#

Bases: LabelStore

Storage for semantic segmentation predictions.

Can store predicted class ID raster and class scores raster as GeoTIFFs, and can optionally vectorize predictions and store them as GeoJSON files.

Attributes

bbox

Bounding box applied to the source.

crs_transformer

Associated CRSTransformer.

__init__(uri: str, crs_transformer: CRSTransformer, class_config: ClassConfig, bbox: Optional[Box] = None, tmp_dir: Optional[str] = None, vector_outputs: Optional[Sequence[VectorOutputConfig]] = None, save_as_rgb: bool = False, discrete_output: bool = True, smooth_output: bool = False, smooth_as_uint8: bool = False, rasterio_block_size: int = 512)[source]#

Constructor.

Parameters
  • uri (str) – Path to directory where the predictions are/will be stored. Smooth scores will be saved as “uri/scores.tif”, discrete labels will be stored as “uri/labels.tif”, and vector outputs will be saved in “uri/vector_outputs/”.

  • crs_transformer (CRSTransformer) – CRS transformer for correctly mapping from pixel coords to map coords.

  • class_config (ClassConfig) – Class config.

  • bbox (Optional[Box], optional) – User-specified crop of the extent. If provided, only labels falling inside it are returned by SemanticSegmentationLabelStore.get_labels(). Must be provided if the corresponding RasterSource has bbox != extent.

  • tmp_dir (Optional[str], optional) – Temporary directory to use. If None, will be auto-generated. Defaults to None.

  • vector_outputs (Optional[Sequence[VectorOutputConfig]], optional) – List of VectorOutputConfig’s containing vectorization configuration information. Only classes for which a VectorOutputConfig is specified will be saved as vectors. If None, no vector outputs will be produced. Defaults to None.

  • save_as_rgb (bool, optional) – If True, saves labels as an RGB image, using the class-color mapping in the class_config. Defaults to False.

  • discrete_output (bool, optional) – If True, saves labels as a raster of class IDs (one band). Defaults to False.

  • smooth_output (bool, optional) – If True, saves labels as a raster of class scores (one band for each class). Defaults to False.

  • smooth_as_uint8 (bool, optional) – If True, stores smooth class scores as np.uint8 (0-255) values rather than as np.float32 discrete labels, to help save memory/disk space. Defaults to False.

  • rasterio_block_size (int, optional) – Value to set blockxsize and blockysize to. Defaults to 512.

Methods

__init__(uri, crs_transformer, class_config)

Constructor.

get_discrete_labels()

Get all labels.

get_labels()

Get all labels.

get_scores()

Get all scores.

save(labels[, profile])

Save labels to disk.

set_bbox(bbox)

Set self.extent to the given value.

write_discrete_raster_output(out_profile, ...)

write_smooth_raster_output(out_profile, ...)

write_vector_outputs(labels, vector_output_dir)

Write vectorized outputs for all configs in self.vector_outputs.

__init__(uri: str, crs_transformer: CRSTransformer, class_config: ClassConfig, bbox: Optional[Box] = None, tmp_dir: Optional[str] = None, vector_outputs: Optional[Sequence[VectorOutputConfig]] = None, save_as_rgb: bool = False, discrete_output: bool = True, smooth_output: bool = False, smooth_as_uint8: bool = False, rasterio_block_size: int = 512)[source]#

Constructor.

Parameters
  • uri (str) – Path to directory where the predictions are/will be stored. Smooth scores will be saved as “uri/scores.tif”, discrete labels will be stored as “uri/labels.tif”, and vector outputs will be saved in “uri/vector_outputs/”.

  • crs_transformer (CRSTransformer) – CRS transformer for correctly mapping from pixel coords to map coords.

  • class_config (ClassConfig) – Class config.

  • bbox (Optional[Box], optional) – User-specified crop of the extent. If provided, only labels falling inside it are returned by SemanticSegmentationLabelStore.get_labels(). Must be provided if the corresponding RasterSource has bbox != extent.

  • tmp_dir (Optional[str], optional) – Temporary directory to use. If None, will be auto-generated. Defaults to None.

  • vector_outputs (Optional[Sequence[VectorOutputConfig]], optional) – List of VectorOutputConfig’s containing vectorization configuration information. Only classes for which a VectorOutputConfig is specified will be saved as vectors. If None, no vector outputs will be produced. Defaults to None.

  • save_as_rgb (bool, optional) – If True, saves labels as an RGB image, using the class-color mapping in the class_config. Defaults to False.

  • discrete_output (bool, optional) – If True, saves labels as a raster of class IDs (one band). Defaults to False.

  • smooth_output (bool, optional) – If True, saves labels as a raster of class scores (one band for each class). Defaults to False.

  • smooth_as_uint8 (bool, optional) – If True, stores smooth class scores as np.uint8 (0-255) values rather than as np.float32 discrete labels, to help save memory/disk space. Defaults to False.

  • rasterio_block_size (int, optional) – Value to set blockxsize and blockysize to. Defaults to 512.

get_discrete_labels() SemanticSegmentationDiscreteLabels[source]#

Get all labels.

Returns

SemanticSegmentationDiscreteLabels

Return type

SemanticSegmentationDiscreteLabels

get_labels() SemanticSegmentationLabels[source]#

Get all labels.

Returns

SemanticSegmentationLabels

Return type

SemanticSegmentationLabels

get_scores() SemanticSegmentationSmoothLabels[source]#

Get all scores.

Returns

SemanticSegmentationSmoothLabels

Return type

SemanticSegmentationSmoothLabels

save(labels: SemanticSegmentationLabels, profile: Optional[dict] = None) None[source]#

Save labels to disk.

More info on rasterio IO: - https://github.com/mapbox/rasterio/blob/master/docs/quickstart.rst - https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html

Parameters
Return type

None

set_bbox(bbox: Box) None[source]#

Set self.extent to the given value.

Note

This method is idempotent.

Parameters
  • extent (Box) – User-specified extent in pixel coordinates.

  • bbox (Box) –

Return type

None

write_discrete_raster_output(out_profile: dict, path: str, labels: SemanticSegmentationLabels) None[source]#
Parameters
Return type

None

write_smooth_raster_output(out_profile: dict, scores_path: str, hits_path: str, labels: SemanticSegmentationSmoothLabels) None[source]#
Parameters
Return type

None

write_vector_outputs(labels: SemanticSegmentationLabels, vector_output_dir: str) None[source]#

Write vectorized outputs for all configs in self.vector_outputs.

Parameters
Return type

None

property bbox: Box#

Bounding box applied to the source.

property crs_transformer: CRSTransformer#

Associated CRSTransformer.