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.

__init__(uri: str, extent: Box, crs_transformer: CRSTransformer, class_config: ClassConfig, 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/”.

  • extent (Box) – The extent of the scene.

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

  • 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.

  • class_config (ClassConfig) – Class config.

  • 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, extent, crs_transformer, ...)

Constructor.

empty_labels(**kwargs)

Returns an empty SemanticSegmentationLabels object.

get_discrete_labels()

Get all labels.

get_labels()

Get all labels.

get_scores()

Get all scores.

save(labels[, profile])

Save labels to disk.

write_discrete_raster_output(out_profile, ...)

write_smooth_raster_output(out_profile, ...)

write_vector_outputs(labels)

Write vectorized outputs for all configs in self.vector_outputs.

__init__(uri: str, extent: Box, crs_transformer: CRSTransformer, class_config: ClassConfig, 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/”.

  • extent (Box) – The extent of the scene.

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

  • 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.

  • class_config (ClassConfig) – Class config.

  • 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.

empty_labels(**kwargs) SemanticSegmentationLabels[source]#

Returns an empty SemanticSegmentationLabels object.

Return type

SemanticSegmentationLabels

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

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) None[source]#

Write vectorized outputs for all configs in self.vector_outputs.

Parameters

labels (SemanticSegmentationLabels) –

Return type

None