class Detection(BaseModelExtraForbid):
Detection record containing annotations and metadata for one object.
It describes a single detected object in an image and can contain various types of annotations and metadata as well as nested sub-detections for hierarchical annotations.
When scale_to_boxes is enabled, keypoints and segmentation data are interpreted relative to the bounding box and rescaled to image-normalized coordinates.
Example
>>> detection = Detection( ... class_name="person", ... instance_id=1, ... metadata={ ... "category": Category("adult"), ... }, ... boundingbox={ ... "x": 0.1, ... "y": 0.2, ... "w": 0.3, ... "h": 0.4, ... }, ... instance_segmentation={ ... "mask": np.array([[0, 1], [1, 0]]), ... }, ... sub_detections={ ... "face": { ... "class_name": "face", ... "boundingbox": { ... "x": 0.2, ... "y": 0.3, ... "w": 0.1, ... "h": 0.1, ... }, ... "keypoints": { ... "keypoints": [ ... (0.25, 0.35, 2), # left eye ... (0.3, 0.35, 2), # right eye ... ], ... }, ... "metadata": { ... "expression": Category("happy"), ... "eye_color": Category("blue"), ... }, ... }, ... }, ... )
| Method | get |
Get all the task type associated with this detection. |
| Instance Variable | array |
Optional array annotation. |
| Instance Variable | boundingbox |
Optional bounding box annotation. |
| Instance Variable | class |
optional class name for the detection. Input data may use the "class" alias. |
| Instance Variable | instance |
Instance identifier. If not provided, the instance IDs will correspond to the order in which the detections were added to the dataset. Note that this might lead to incorrect pairing of instance annotations if individual detection types are added separately and in an inconsistent order across records:... |
| Instance Variable | instance |
Optional instance segmentation annotation. |
| Instance Variable | keypoints |
Optional keypoint annotation. |
| Instance Variable | metadata |
Metadata values keyed by metadata name. |
| Instance Variable | scale |
Whether annotation coordinates should be rescaled from bounding-box-relative coordinates. |
| Instance Variable | segmentation |
Optional semantic segmentation annotation. |
| Instance Variable | sub |
Nested detections keyed by sub-detection name. |
| Static Method | _check |
Undocumented |
| Method | _rescale |
Undocumented |
| Method | _validate |
Undocumented |
Get all the task type associated with this detection.
Example
>>> detection = Detection( ... class_name="cat", ... boundingbox=BBoxAnnotation(x=0.1, y=0.2, w=0.3, h=0.4), ... metadata={"color": "black"}, ... ) >>> sorted(detection.get_task_types()) ['boundingbox', 'classification', 'metadata/color']
| Returns | |
set[ | Annotation task types and metadata keys. |
Instance identifier. If not provided, the instance IDs will correspond to the order in which the detections were added to the dataset. Note that this might lead to incorrect pairing of instance annotations if individual detection types are added separately and in an inconsistent order across records:
# Without specifying `instance_id`, the # bounding box and keypoint annotation will # not be correctly paired as they are added in separate # detections and in a different order. def generator(): yield { "file": ..., "annotation": {"boundingbox": bbox1}, } yield { "file": ..., "annotation": {"keypoints": kpts2}, } yield { "file": ..., "annotation": {"boundingbox": bbox2}, } yield { "file": ..., "annotation": {"keypoints": kpts1}, }
It is recommended to provide instance IDs if possible and to avoid generating annotations individually in separate detections:
# This is the correct way def generator(): yield { "file": ..., "annotation": { "instance_id": 1, "boundingbox": bbox1 "keypoints": kpts1, }, } yield { "file": ..., "annotation": { "instance_id": 2, "boundingbox": bbox2 "keypoints": kpts2, }, }