annotation_append#
- Dataset.annotation_append(format_string: str = 'XYWH', category_ids_mapping: dict[int, int] | None = None, label_map: dict[int, str] | None = None) AnnotationAppender[source]#
Create a context manager to add detection tensors to the current dataset with the
AnnotationAppender.append()method, 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.Note
The dataset object from which this context manager is created is modified inplace, similar to a list append.
- Parameters:
format_string – format string for incoming bounding boxes. Depend on your detector conventions. 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. Defaults to None
label_map – Optional label map for objects outside the current label map. Must be compatible with the current label map (i.e. no category id clash). Defaults to None.
- Returns:
Context manager to easily add detection tensors
- Return type:
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'} >>> with example.annotation_append( ... format_string="xyxy", label_map={1: "new_class"} ... ) as appender: ... appender.append( ... image_id=0, ... bbox_coordinates=np.array([[0, 0, 0.5, 0.5]]), ... category_id=15, ... confidence=0.5, ... other_attribute=0, ... ) ... appender.append( ... image_id=[1, 0], ... bbox_coordinates=np.array( ... [[0.1, 0.1, 0.9, 0.9], [0.2, 0.3, 0.5, 0.5]] ... ), ... category_id=np.array([1, 15]), ... confidence=np.array([0.2, 0.3]), ... other_attribute=np.array([3, 4]), ... ) >>> example Dataset object containing 2 images and 5 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_height confidence other_attribute id ... 0 0 step 15 ... 42.673983 NaN NaN 1 0 why 19 ... 122.602211 NaN NaN 2 0 step 15 ... 68.000000 0.5 0.0 3 1 new_class 1 ... 133.600000 0.2 3.0 4 0 step 15 ... 27.200000 0.3 4.0 [5 rows x 10 columns] Label map : {1: 'new_class', 15: 'step', 19: 'why', 25: 'interview'}