otx.api.entities.annotation#

This module define the annotation entity.

Classes

Annotation(shape, labels[, id])

Base class for annotation objects.

AnnotationSceneEntity(annotations, kind[, ...])

This class represents a user annotation or a result (prediction).

AnnotationSceneKind(value)

AnnotationSceneKinds for an Annotation object.

NullAnnotationSceneEntity()

Represents 'AnnotationSceneEntity not found.

class otx.api.entities.annotation.Annotation(shape: ShapeEntity, labels: List[ScoredLabel], id: ID | None = None)[source]#

Bases: object

Base class for annotation objects.

Parameters:
  • shape (ShapeEntity) – the shape of the annotation

  • labels (List[ScoredLabel]) – the labels of the annotation

  • id (Optional[ID]) – the id of the annotation

append_label(label: ScoredLabel) None[source]#

Appends the scored label to the annotation.

Parameters:

label (ScoredLabel) – the scored label to be appended to the annotation

get_label_ids(include_empty: bool = False) Set[ID][source]#

Get a set of ID’s of labels that are assigned to this annotation.

Parameters:

include_empty (bool) – set to True to include empty label (if exists) in the output. Defaults to False.

Returns:

Set of label id’s in annotation

get_labels(include_empty: bool = False) List[ScoredLabel][source]#

Get scored labels that are assigned to this annotation.

Parameters:

include_empty (bool) – set to True to include empty label (if exists) in the output. Defaults to False.

Returns:

List of labels in annotation

set_labels(labels: List[ScoredLabel]) None[source]#

Sets the labels of the annotation to be the input of the function.

Parameters:

labels (List[ScoredLabel]) – the scored labels to be set as annotation labels

property id#

DEPRECATED.

property id_#

Returns the id for the annotation.

property shape: ShapeEntity#

Returns the shape that is in the annotation.

class otx.api.entities.annotation.AnnotationSceneEntity(annotations: List[Annotation], kind: AnnotationSceneKind, editor: str = '', creation_date: datetime | None = None, id: ID | None = None)[source]#

Bases: object

This class represents a user annotation or a result (prediction).

It serves as a collection of shapes, with a relation to the media entity.

Example

Creating an annotation:

>>> from otx.api.entities.annotation import Annotation, AnnotationSceneEntity, AnnotationSceneKind
>>> from otx.api.entities.shapes.rectangle import Rectangle
>>> box = Rectangle(x1=0.0, y1=0.0, x2=0.5, y2=0.5)  # Box covering top-left quart of image
>>> AnnotationSceneEntity(annotations=[Annotation(shape=box, labels=[])], kind=AnnotationSceneKind.ANNOTATION)
Parameters:
  • annotations (List[Annotation]) – List of annotations in the scene

  • kind (AnnotationSceneKind) – Kind of the annotation scene. E.g. AnnotationSceneKind.ANNOTATION.

  • editor (str) – The user that made this annotation scene object.

  • creation_date (Optional[datetime.datetime]) – Creation date of annotation scene entity. If None, current time is used. Defaults to None.

  • id (Optional[ID]) – ID of AnnotationSceneEntity. If None a new ID is created. Defaults to None.

append_annotation(annotation: Annotation) None[source]#

Appends the passed annotation to the list of annotations present in the AnnotationSceneEntity object.

append_annotations(annotations: List[Annotation]) None[source]#

Adds a list of annotations to the annotation scene.

contains_any(labels: List[LabelEntity]) bool[source]#

Checks whether the annotation contains any labels in the input parameter.

Parameters:

labels (List[LabelEntity]) – List of labels to compare to.

Returns:

True if there is any intersection between self.get_labels(include_empty=True) with labels.

Return type:

bool

get_label_ids(include_empty: bool = False) Set[ID][source]#

Returns a set of the ID’s of unique labels which appear in this annotation scene.

Parameters:

include_empty (bool) – Set to True to include empty label (if exists) in the output. Defaults to False.

Returns:

a set of the ID’s of labels which appear in this annotation.

Return type:

Set[ID]

get_labels(include_empty: bool = False) List[LabelEntity][source]#

Returns a list of unique labels which appear in this annotation scene.

Parameters:

include_empty (bool) – Set to True to include empty label (if exists) in the output. Defaults to False.

Returns:

a list of labels which appear in this annotation.

Return type:

List[LabelEntity]

property annotations: List[Annotation]#

Return the Annotations that are present in the AnnotationSceneEntity.

property creation_date: datetime#

Returns the creation date of the AnnotationSceneEntity object.

property editor_name: str#

Returns the editor’s name that made the AnnotationSceneEntity object.

property id#

DEPRECATED.

property id_: ID#

Returns the ID of the AnnotationSceneEntity.

property kind: AnnotationSceneKind#

Returns the AnnotationSceneKind of the AnnotationSceneEntity.

property shapes: List[ShapeEntity]#

Returns all shapes that are inside the annotations of the AnnotationSceneEntity.

class otx.api.entities.annotation.AnnotationSceneKind(value)[source]#

Bases: Enum

AnnotationSceneKinds for an Annotation object.

ANNOTATION = 1#

ANNOTATION represents user annotation

EVALUATION = 3#

EVALUATION represents analysis result for evaluation purposes, which will NOT be shown to the user

INTERMEDIATE = 4#

INTERMEDIATE represents intermediary state. This is used when the analysis is being transferred from one task to another. This will not be shown to the user. This state will be changed to either PREDICTION or EVALUATION at the end of analysis process.

NONE = 0#

NONE represents NULLAnnotationScene’s (See NullAnnotationScene)

PREDICTION = 2#

PREDICTION represents analysis result, which will be shown to the user

TASK_PREDICTION = 5#

TASK_PREDICTION represents analysis results for a single task

class otx.api.entities.annotation.NullAnnotationSceneEntity[source]#

Bases: AnnotationSceneEntity

Represents ‘AnnotationSceneEntity not found.