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
Bounding box applied to the source.
Associated
CRSTransformer
.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 toFalse
.
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.
- __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 toFalse
.
- 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:
- 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. IfNone
, cells are assumed to be sliding windows of size and stridecell_sz
(specified inChipClassificationLabelSourceConfig
). Defaults toNone
.- Returns:
Labels (in global coords).
- Return type:
- 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.
- set_bbox(bbox: Box) None [source]#
Set self.extent to the given value.
Note
This method is idempotent.
- validate_labels(df: GeoDataFrame) None [source]#
- Parameters:
df (GeoDataFrame) –
- Return type:
None
- property crs_transformer: CRSTransformer#
Associated
CRSTransformer
.