add_detection_annotation#
- Dataset.add_detection_annotation(image_id: int | Sequence[int] | ndarray, bbox_coordinates: Sequence[float] | Sequence[Sequence[float]] | ndarray, category_id: ndarray | int | Sequence[int], format_string: str = 'XYWH', 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 | ndarray | Sequence[float] | Sequence[str]) Self[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:
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
category_id – category of each detection. Label will be deduced from dataset’s label map
format_string – format of coordinates, whether coordinates are relatives, using corner points of the box, box dimensions, etc. See
import_bbox()for more infoinplace – if set to True, will modify the dataset inplace and return self. 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. Defaults to None
confidence – Optional field for confidence, in the case annotations are actually predictions. Defaults to None.
**other_columns – kwargs of additional optional 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:
A new Dataset with appended annotations to
self.annotationsifinplaceis False, or itself otherwise.
Example
>>> from lours.utils.doc_utils import dummy_dataset >>> example = dummy_dataset() >>> example Dataset object containing 2 images and 2 objects Name : inside_else_memory Images root : such/serious Images : width height relative_path type split id 0 342 136 help/me.jpeg .jpeg train 1 377 167 whatever/wait.png .png train Annotations : image_id category_str category_id ... box_y_min box_width box_height id ... 0 0 step 15 ... 73.932999 71.552480 42.673983 1 0 why 19 ... 4.567638 248.551257 122.602211 [2 rows x 8 columns] Label map : {15: 'step', 19: 'why', 25: 'interview'} >>> example.add_detection_annotation( ... image_id=0, ... bbox_coordinates=[0, 0, 0.5, 0.5], ... format_string="xyxy", ... category_id=14, ... confidence=0.5, ... ) Dataset object containing 2 images and 3 objects Name : inside_else_memory Images root : such/serious Images : width height relative_path type split id 0 342 136 help/me.jpeg .jpeg train 1 377 167 whatever/wait.png .png train Annotations : image_id category_str category_id ... box_width box_height confidence id ... 0 0 step 15 ... 71.552480 42.673983 NaN 1 0 why 19 ... 248.551257 122.602211 NaN 2 0 14 14 ... 171.000000 68.000000 0.5 [3 rows x 9 columns] Label map : {14: '14', 15: 'step', 19: 'why', 25: 'interview'}