NpBoxList#

class NpBoxList[source]#

Bases: object

A list of bounding boxes as a [y_min, x_min, y_max, x_max] numpy array.

It is assumed that all bounding boxes within a given list correspond to a single image. Optionally, users can add additional related fields (such as objectness/classification scores).

__init__(data: ndarray)[source]#

Constructor.

Parameters:

data (np.ndarray) – Box coords as a [N, 4] numpy array.

Raises:
  • ValueError – If bbox data is not a numpy array.

  • ValueError – If invalid dimensions for bbox data.

Methods

__init__(data)

Constructor.

add_field(name, data)

Add data to a specified field.

get()

Shorthand for get_field('boxes').

get_coordinates()

Get corner coordinates of boxes.

get_extra_fields()

Return all non-box fields.

get_field(name)

Get data for field.

has_field(field)

num_boxes()

Return number of boxes held in collections.

__init__(data: ndarray)[source]#

Constructor.

Parameters:

data (np.ndarray) – Box coords as a [N, 4] numpy array.

Raises:
  • ValueError – If bbox data is not a numpy array.

  • ValueError – If invalid dimensions for bbox data.

add_field(name: str, data: ndarray) None[source]#

Add data to a specified field.

Parameters:
  • name (str) – Field name.

  • data (np.ndarray) – Field data: box coords as a [N, 4] numpy array.

Raises:
  • ValueError – If name already exists.

  • ValueError – If the dimension of the field data does not matche the number of boxes.

Return type:

None

get()[source]#

Shorthand for get_field(‘boxes’).

get_coordinates() tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]#

Get corner coordinates of boxes.

Returns:

a 4-tuple of 1-d numpy arrays [y_min, x_min, y_max, x_max].

Return type:

tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]

get_extra_fields() list[str][source]#

Return all non-box fields.

Return type:

list[str]

get_field(name: str) ndarray[source]#

Get data for field.

Parameters:

name (str) – Field name.

Returns:

The data associated with the field.

Return type:

np.ndarray

Raises:

ValueError – if invalid field.

has_field(field) bool[source]#
Return type:

bool

num_boxes() int[source]#

Return number of boxes held in collections.

Return type:

int