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.

get_boxes()

Return list of Boxes.

get_class_ids()

get_npboxes()

get_overlapping(labels, window[, ...])

Return subset of labels that overlap with window.

get_scores()

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.

make_empty()

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_boxlist()

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
Return type

ObjectDetectionLabels

filter_by_aoi(aoi_polygons: Iterable[Polygon])[source]#

Returns a copy of these labels filtered by a given set of AOI polygons

Parameters
  • by (aoi_polygons - A list of AOI polygons to filter) –

  • coordinates. (in pixel) –

  • aoi_polygons (Iterable[Polygon]) –

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
  • geojson (dict) – (dict) normalized GeoJSON (see VectorSource)

  • extent (Optional[Box]) – (Box) in pixel coords

Returns

ObjectDetectionLabels

Return type

ObjectDetectionLabels

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.

Parameters
  • windows (Iterable[Box]) – Boxes in pixel coords, specifying chips in the raster.

  • predictions (Iterable[Any]) – The model predictions for each chip specified by the windows.

Returns

An object of the Label subclass on which this method is

called.

Return type

Labels

get_boxes() List[Box][source]#

Return list of Boxes.

Return type

List[Box]

get_class_ids() ndarray[source]#
Return type

ndarray

get_npboxes() ndarray[source]#
Return type

ndarray

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

ObjectDetectionLabels

get_scores() ndarray[source]#
Return type

ndarray

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.

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

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

Parameters
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

Labels

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.

Parameters
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

ObjectDetectionLabels

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

to_boxlist() BoxList[source]#
Return type

BoxList

to_dict() dict[source]#

Returns a dict version of these labels.

The Dict has a Box as a key, and a tuple of (class_id, score) as the values.

Return type

dict