ChipClassificationLabelSource#

class ChipClassificationLabelSource[source]#

Bases: LabelSource

A source of chip classification labels.

Ideally the vector_source contains a square for each cell in the grid. But in reality, it can be difficult to label imagery in such an exhaustive way. So, this can also handle sources with non-overlapping polygons that do not necessarily cover the entire extent. It infers the grid of cells and associated class_ids using the extent and options if infer_cells is set to True.

Attributes

bbox

Bounding box applied to the source.

crs_transformer

Associated CRSTransformer.

extent

Extent of the LabelSource.

__init__(label_source_config: ChipClassificationLabelSourceConfig, vector_source: VectorSource, bbox: rastervision.core.box.Box | None = None, lazy: bool = False)[source]#

Constructor.

Parameters:
  • label_source_config (ChipClassificationLabelSourceConfig) – Config for class inference.

  • vector_source (VectorSource) – Source of vector labels.

  • bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. If None, the full extent available in the source file is used.

  • lazy (bool) – If True, labels are not populated during initialization. Defaults to False.

Methods

__init__(label_source_config, vector_source)

Constructor.

get_labels([window])

Return label for a window, inferring it if not already known.

infer_cells([cells])

Infer labels for a list of cells.

populate_labels([cells])

Populate self.labels by either reading or inferring.

set_bbox(bbox)

Set self.extent to the given value.

validate_labels(df)

__getitem__(key: Any) int[source]#

Return class ID for a window, inferring it if not already known.

Parameters:

key (Any) –

Return type:

int

__init__(label_source_config: ChipClassificationLabelSourceConfig, vector_source: VectorSource, bbox: rastervision.core.box.Box | None = None, lazy: bool = False)[source]#

Constructor.

Parameters:
  • label_source_config (ChipClassificationLabelSourceConfig) – Config for class inference.

  • vector_source (VectorSource) – Source of vector labels.

  • bbox (rastervision.core.box.Box | None) – User-specified crop of the extent. If None, the full extent available in the source file is used.

  • lazy (bool) – If True, labels are not populated during initialization. Defaults to False.

get_labels(window: rastervision.core.box.Box | None = None) ChipClassificationLabels[source]#

Return label for a window, inferring it if not already known.

If window is None, returns all labels.

Parameters:

window (rastervision.core.box.Box | None) –

Return type:

ChipClassificationLabels

infer_cells(cells: Optional[Iterable[Box]] = None) ChipClassificationLabels[source]#

Infer labels for a list of cells.

Cells are assumed to be in bbox coords as opposed to global coords and are converted to global coords before inference. The returned labels are in global coords. Only cells whose labels are not already known are inferred.

Parameters:

cells (Optional[Iterable[Box]]) – Cells (in bbox coords) whose labels are to be inferred. If None, cells are assumed to be sliding windows of size and stride cell_sz (specified in ChipClassificationLabelSourceConfig). Defaults to None.

Returns:

Labels (in global coords).

Return type:

ChipClassificationLabels

populate_labels(cells: Optional[Iterable[Box]] = None) None[source]#

Populate self.labels by either reading or inferring.

If cfg.infer_cells is True or specific cells are given, the labels are inferred. Otherwise, they are read from the geojson.

Parameters:

cells (Optional[Iterable[Box]]) –

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

validate_labels(df: GeoDataFrame) None[source]#
Parameters:

df (GeoDataFrame) –

Return type:

None

property bbox: Box#

Bounding box applied to the source.

property crs_transformer: CRSTransformer#

Associated CRSTransformer.

property extent: Box#

Extent of the LabelSource.