SemanticSegmentationLabelStore#
- class SemanticSegmentationLabelStore[source]#
Bases:
LabelStoreStorage 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
Bounding box applied to the source.
Associated
CRSTransformer.- __init__(uri: str, crs_transformer: CRSTransformer, class_config: ClassConfig, bbox: rastervision.core.box.Box | None = None, tmp_dir: str | None = None, vector_outputs: Sequence[VectorOutputConfig] | None = 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 (rastervision.core.box.Box | None) – User-specified crop of the extent. If provided, only labels falling inside it are returned by
SemanticSegmentationLabelStore.get_labels(). Must be provided if the correspondingRasterSourcehasbbox != extent.tmp_dir (str | None) – Temporary directory to use. If
None, will be auto-generated. Defaults toNone.vector_outputs (Sequence[VectorOutputConfig] | None) – List of VectorOutputConfig’s containing vectorization configuration information. Only classes for which a
VectorOutputConfigis specified will be saved as vectors. IfNone, no vector outputs will be produced. Defaults toNone.save_as_rgb (bool) – If
True, saves labels as an RGB image, using the class-color mapping in theclass_config. Defaults toFalse.discrete_output (bool) – If
True, saves labels as a raster of class IDs (one band). Defaults toFalse.smooth_output (bool) – If
True, saves labels as a raster of class scores (one band for each class). Defaults toFalse.smooth_as_uint8 (bool) – If
True, stores smooth class scores asnp.uint8(0-255) values rather than asnp.float32discrete labels, to help save memory/disk space. Defaults toFalse.rasterio_block_size (int) – Value to set
blockxsizeandblockysizeto. Defaults to512.
Methods
__init__(uri, crs_transformer, class_config)Constructor.
build_rasterio_gtiff_profile(labels)Get all labels.
Get all labels.
Get all scores.
merge_with_old_scores(labels)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_output(vo, mask, vector_output_dir)Write vector output for a single
VectorOutputConfig.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: rastervision.core.box.Box | None = None, tmp_dir: str | None = None, vector_outputs: Sequence[VectorOutputConfig] | None = 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 (rastervision.core.box.Box | None) – User-specified crop of the extent. If provided, only labels falling inside it are returned by
SemanticSegmentationLabelStore.get_labels(). Must be provided if the correspondingRasterSourcehasbbox != extent.tmp_dir (str | None) – Temporary directory to use. If
None, will be auto-generated. Defaults toNone.vector_outputs (Sequence[VectorOutputConfig] | None) – List of VectorOutputConfig’s containing vectorization configuration information. Only classes for which a
VectorOutputConfigis specified will be saved as vectors. IfNone, no vector outputs will be produced. Defaults toNone.save_as_rgb (bool) – If
True, saves labels as an RGB image, using the class-color mapping in theclass_config. Defaults toFalse.discrete_output (bool) – If
True, saves labels as a raster of class IDs (one band). Defaults toFalse.smooth_output (bool) – If
True, saves labels as a raster of class scores (one band for each class). Defaults toFalse.smooth_as_uint8 (bool) – If
True, stores smooth class scores asnp.uint8(0-255) values rather than asnp.float32discrete labels, to help save memory/disk space. Defaults toFalse.rasterio_block_size (int) – Value to set
blockxsizeandblockysizeto. Defaults to512.
- build_rasterio_gtiff_profile(labels: SemanticSegmentationLabels) dict[source]#
- Parameters
labels (SemanticSegmentationLabels) –
- Return type
- get_discrete_labels() SemanticSegmentationDiscreteLabels[source]#
Get all labels.
- Returns
SemanticSegmentationDiscreteLabels
- Return type
- get_labels() SemanticSegmentationLabels[source]#
Get all labels.
- Returns
SemanticSegmentationLabels
- Return type
- get_scores() SemanticSegmentationSmoothLabels[source]#
Get all scores.
- Returns
SemanticSegmentationSmoothLabels
- Return type
- merge_with_old_scores(labels: SemanticSegmentationSmoothLabels) SemanticSegmentationSmoothLabels[source]#
- Parameters
labels (SemanticSegmentationSmoothLabels) –
- Return type
- save(labels: SemanticSegmentationLabels, profile: dict | None = 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
- (labels) –
labels (SemanticSegmentationLabels) –
profile (dict | None) –
- Return type
None
- set_bbox(bbox: Box) None[source]#
Set self.extent to the given value.
Note
This method is idempotent.
- write_discrete_raster_output(out_profile: dict, path: str, labels: SemanticSegmentationLabels) None[source]#
- Parameters
out_profile (dict) –
path (str) –
labels (SemanticSegmentationLabels) –
- Return type
None
- write_smooth_raster_output(out_profile: dict, scores_path: str, hits_path: str, labels: SemanticSegmentationSmoothLabels) None[source]#
- Parameters
out_profile (dict) –
scores_path (str) –
hits_path (str) –
labels (SemanticSegmentationSmoothLabels) –
- Return type
None
- write_vector_output(vo: VectorOutputConfig, mask: ndarray, vector_output_dir: str) None[source]#
Write vector output for a single
VectorOutputConfig.- Parameters
vo (VectorOutputConfig) –
mask (ndarray) –
vector_output_dir (str) –
- 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
labels (SemanticSegmentationLabels) –
vector_output_dir (str) –
- Return type
None
- property crs_transformer: CRSTransformer#
Associated
CRSTransformer.