ObjectDetectionLabels#
- class ObjectDetectionLabels[source]#
Bases:
Labels
A set of boxes and associated class_ids and scores.
Implemented using the Tensorflow Object Detection API’s BoxList class.
- __init__(npboxes: array, class_ids: array, scores: Optional[array] = None)[source]#
Construct a set of object detection labels.
- Parameters
npboxes (array) – float numpy array of size nx4 with cols ymin, xmin, ymax, xmax. Should be in pixel coordinates within the global frame of reference.
class_ids (array) – int numpy array of size n with class ids
scores (Optional[array]) – float numpy array of size n
Methods
__init__
(npboxes, class_ids[, scores])Construct a set of object detection labels.
assert_equal
(expected_labels)concatenate
(labels1, labels2)Return concatenation of labels.
filter_by_aoi
(aoi_polygons)Returns a copy of these labels filtered by a given set of AOI polygons
from_boxlist
(boxlist)Make ObjectDetectionLabels from BoxList object.
from_geojson
(geojson[, extent])Convert GeoJSON to ObjectDetectionLabels object.
from_predictions
(windows, predictions)Instantiate from windows and their corresponding predictions.
Return list of Boxes.
get_overlapping
(labels, window[, ...])Return subset of labels that overlap with window.
global_to_local
(npboxes, window)Convert from global to local coordinates.
local_to_global
(npboxes, window)Convert from local to global coordinates.
local_to_normalized
(npboxes, window)Convert from local to normalized coordinates.
Instantiate an empty instance of this class.
normalized_to_local
(npboxes, window)Convert from normalized to local coordinates.
prune_duplicates
(labels, score_thresh, ...)Remove duplicate boxes.
save
(uri, class_config, crs_transformer)Save labels as a GeoJSON file.
to_dict
()Returns a dict version of these labels.
- __init__(npboxes: array, class_ids: array, scores: Optional[array] = None)[source]#
Construct a set of object detection labels.
- Parameters
npboxes (array) – float numpy array of size nx4 with cols ymin, xmin, ymax, xmax. Should be in pixel coordinates within the global frame of reference.
class_ids (array) – int numpy array of size n with class ids
scores (Optional[array]) – float numpy array of size n
- assert_equal(expected_labels: ObjectDetectionLabels)[source]#
- Parameters
expected_labels (ObjectDetectionLabels) –
- static concatenate(labels1: ObjectDetectionLabels, labels2: ObjectDetectionLabels) ObjectDetectionLabels [source]#
Return concatenation of labels.
- Parameters
labels1 (ObjectDetectionLabels) – ObjectDetectionLabels
labels2 (ObjectDetectionLabels) – ObjectDetectionLabels
- Return type
- filter_by_aoi(aoi_polygons: Iterable[Polygon])[source]#
Returns a copy of these labels filtered by a given set of AOI polygons
- static from_boxlist(boxlist: BoxList)[source]#
Make ObjectDetectionLabels from BoxList object.
- Parameters
boxlist (BoxList) –
- static from_geojson(geojson: dict, extent: Optional[Box] = None) ObjectDetectionLabels [source]#
Convert GeoJSON to ObjectDetectionLabels object.
If extent is provided, filter out the boxes that lie “more than a little bit” outside the extent.
- Parameters
- Returns
ObjectDetectionLabels
- Return type
- classmethod from_predictions(windows: Iterable[Box], predictions: Iterable[Any]) Labels #
Instantiate from windows and their corresponding predictions.
This makes no assumptions about the type or format of the predictions. Subclasses should implement the __setitem__ method to correctly handle the predictions.
- static get_overlapping(labels: ObjectDetectionLabels, window: Box, ioa_thresh: float = 1e-06, clip: bool = False) ObjectDetectionLabels [source]#
Return subset of labels that overlap with window.
- Parameters
labels (ObjectDetectionLabels) – ObjectDetectionLabels
window (Box) – Box
ioa_thresh (float) – the minimum IOA for a box to be considered as overlapping
clip (bool) – if True, clip label boxes to the window
- Return type
- static global_to_local(npboxes: ndarray, window: Box)[source]#
Convert from global to local coordinates.
The global coordinates are row/col within the extent of a RasterSource. The local coordinates are row/col within the window frame of reference.
- static local_to_global(npboxes: ndarray, window: Box)[source]#
Convert from local to global coordinates.
The local coordinates are row/col within the window frame of reference. The global coordinates are row/col within the extent of a RasterSource.
- static local_to_normalized(npboxes: ndarray, window: Box)[source]#
Convert from local to normalized coordinates.
The local coordinates are row/col within the window frame of reference. Normalized coordinates range from 0 to 1 on each (height/width) axis.
- classmethod make_empty() ObjectDetectionLabels [source]#
Instantiate an empty instance of this class.
- Returns
- An object of the Label subclass on which this method is
called.
- Return type
- static normalized_to_local(npboxes: ndarray, window: Box)[source]#
Convert from normalized to local coordinates.
Normalized coordinates range from 0 to 1 on each (height/width) axis. The local coordinates are row/col within the window frame of reference.
- static prune_duplicates(labels: ObjectDetectionLabels, score_thresh: float, merge_thresh: float) ObjectDetectionLabels [source]#
Remove duplicate boxes.
Runs non-maximum suppression to remove duplicate boxes that result from sliding window prediction algorithm.
- Parameters
labels (ObjectDetectionLabels) – ObjectDetectionLabels
score_thresh (float) – the minimum allowed score of boxes
merge_thresh (float) – the minimum IOA allowed when merging two boxes together
- Returns
ObjectDetectionLabels
- Return type
- save(uri: str, class_config: ClassConfig, crs_transformer: CRSTransformer) None [source]#
Save labels as a GeoJSON file.
- Parameters
uri (str) – URI of the output file.
class_config (ClassConfig) – ClassConfig to map class IDs to names.
crs_transformer (CRSTransformer) – CRSTransformer to convert from pixel-coords to map-coords before saving.
- Return type
None