annotations_appender#
Functions
Add one or multiple detection annotations to the current dataset. |
|
Broadcast together detection annotation attributes. |
Classes
|
Context manager to easily add detection tensors, as if the Dataset was a list after the appending is finished, the appender construct big numpy arrays to concatenate to the dataset's annotations dataframe |
- class AnnotationAppender(dataset: Dataset, format_string: str = 'XYWH', category_ids_mapping: dict[int, int] | None = None, label_map: dict[int, str] | None = None)[source]#
Context manager to easily add detection tensors, as if the Dataset was a list after the appending is finished, the appender construct big numpy arrays to concatenate to the dataset’s annotations dataframe
Main constructor.
- Parameters:
dataset – dataset the annotations will be appended to.
format_string – String describing bounding box format. Defaults to “XYWH”.
category_ids_mapping – Optional dictionary to map annotated category ids into the right ids. This is useful for example when a neural network can only use a contiguous label map.
label_map – Optional dictionary to provide
category_id -> ``category_strmapping for additional categories in appended annotations. Defaults to None.
- append(image_id: int | Sequence[int] | ndarray, bbox_coordinates: ndarray | Sequence[float], category_id: int | Sequence[int] | ndarray, confidence: float | ndarray | Sequence[float] | None = None, **other: float | str | bool | Sequence[float] | Sequence[str] | Sequence[bool] | ndarray) None[source]#
Append annotations for a particular image id. Everything except image id is expected to be a numpy array. Note that in addition to the regular bounding boxes coordinates, category and confidence, you can add other fields as long as they are numpy array of the same length. If no column exist in the dataset’s annotations dataframe, it will be created (setting the already existing annotations to NaN for this column)
- Parameters:
image_id – id or 1D array of shapes [N] of ids of image corresponding to each annotation to be appended
bbox_coordinates – 2D numpy array of shape [N, 4] corresponding to the bounding box coordinates
category_id – hashable value or 1D numpy array of shape [N] corresponding to the category of each bounding box
confidence – when dealing with the special case of predictions, 1D numpy array of shape [N] corresponding to the confidence of the prediction, which can also be a float if N == 1. None otherwise. Defaults to None.
**other – Other possible fields to the annotation
- Raises:
ValueError – raised when the given numpy arrays are not of the same length, or if bounding box coordinates are not a 2D array with 4 columns.
ValueError – raised when the given image id is not present in the dataset’s image dataframe
- add_detection_annotation(input_dataset: D, image_id: int | Sequence[int] | ndarray, bbox_coordinates: Sequence[float] | Sequence[Sequence[float]] | ndarray, format_string: str, category_id: ndarray | int | Sequence[int], inplace: bool = False, label_map: dict[int, str] | None = None, category_ids_mapping: dict[int, int] | None = None, confidence: float | ndarray | Sequence[float] | None = None, **other_columns: float | str | bool | Sequence[float] | Sequence[str] | Sequence[bool] | ndarray) D[source]#
Add one or multiple detection annotations to the current dataset. In the case of a single annotation, every option can be a single value, but in the case of multiple annotations, every option needs to be an array of such values, and every array needs to be the same length.
Note
In additions to the following options, you can add other fields as well, with keyword arguments.
- Parameters:
input_dataset – Dataset to which we want to add new annotations
image_id – image identifier to link each detection to the corresponding image
bbox_coordinates – list of coordinates for the bounding box. Can follow any compatible format, as long as it is given in the next format
format_string – format of coordinates, whether coordinates are relatives, using corner points of the box, box dimensions, etc. See
import_bbox()for more infocategory_id – category of each detection. Label will be deduced from dataset’s label map
inplace – if set to True, will modify the dataset in place and return itself. Else, will return a modified Dataset. Defaults to False.
label_map – In the case the current dataset’s label map is incomplete, merge it with this new label map. current label map and new label map must be compatible, see
merge_label_maps(). Defaults to None.category_ids_mapping – Optional dictionary to map annotated category ids into the right ids. This is useful for example when a neural network can only use a contiguous label map.
confidence – Optional field for confidence, in the case annotations are actually predictions. Must the same length as bbox_coordinates. In the case of a single prediction, can also be a float. Defaults to None.
**other_columns – Other column representing custom fields.
- Raises:
ValueError – raised when giving numpy arrays are not the same number of elements, or if the bounding box coordinates is not of the shape either [4], or [N, 4]
- Returns:
If
inplaceis False, new dataset object with appended annotations. Otherwise, the updatedinput_dataset.
- broadcast_annotations(image_id: int | Sequence[int] | ndarray, bbox_coordinates: ndarray | Sequence[float] | Sequence[Sequence[float]], category_id: int | ndarray | Sequence[int], confidence: float | ndarray | Sequence[float] | None = None, **other: ndarray | float | str | bool | Sequence[float] | Sequence[str] | Sequence[bool]) dict[str, ndarray][source]#
Broadcast together detection annotation attributes.
Every attribute except
bbox_coordinatescan be only 1 element, and will be duplicated to match the length ofbbox_coordinates.If its more than 1 element, the length must match the length of
bbox_coordinates- Parameters:
image_id – id or 1D array of shapes [N] of ids of image corresponding to each annotation to be appended
bbox_coordinates – 2D numpy array of shape [N, 4] or [N, 2] (for a keypoint) corresponding to the bounding box coordinates. Can also be of the shape [4] or [2] if there is only one bounding box/keypoint
category_id – int value or 1D numpy array of shape [N] corresponding to the category of each bounding box
confidence – when dealing with the special case of predictions, 1D numpy array of shape [N] corresponding to the confidence of the prediction. None otherwise. Defaults to None.
**other – Other possible fields to the annotation
- Raises:
ValueError – Will be raised if the bbox_coordinates shape is not [N, 4] [N, 2] or [2] or [4]
ValueError – Will be raised if the values to broadcast are not scalar or array of size [1] or size [N]
- Returns:
dictionary with the annotation attribute name as keys (“image_id”, “category_id”, etc) and the broadcast of values as numpy arrays as values.