otx.api.entities.result_media#

This module implements the ResultMediaEntity.

Classes

ResultMediaEntity(name, type, ...[, roi, label])

Represents a media (e.g. an image which was generated by a task).

class otx.api.entities.result_media.ResultMediaEntity(name: str, type: str, annotation_scene: AnnotationSceneEntity, numpy: ndarray, roi: Annotation | None = None, label: LabelEntity | None = None)[source]#

Bases: IMetadata

Represents a media (e.g. an image which was generated by a task).

For instance, a ResultMediaEntity could be an attention map generated by a classification task.

The result media contains media data, which is associated with a otx.api.entities.annotation.AnnotationSceneEntity and related to an optional otx.api.entities.label.LabelEntity.

Example

>>> from otx.api.entities.annotation import (
    Annotation,
    AnnotationSceneEntity,
    AnnotationSceneKind,
    )
>>> from otx.api.entities.id import ID
>>> from otx.api.entities.label import Domain, LabelEntity
>>> from otx.api.entities.result_media import ResultMediaEntity
>>> from otx.api.entities.scored_label import LabelSource, ScoredLabel
>>> from otx.api.entities.shapes.rectangle import Rectangle
>>> source = LabelSource(
        user_id="user_entity", model_id=ID("efficientnet"), model_storage_id=ID("efficientnet-storage")
        )
>>> falcon_label = LabelEntity(name="Falcon", domain=Domain.DETECTION)
>>> eagle_label = LabelEntity(name="Eagle", domain=Domain.DETECTION)
>>> falcon_bb = Rectangle(x1=0.0, y1=0.0, x2=0.5, y2=0.5)
>>> falcon_scored_label = ScoredLabel(label=falcon_label, probability=0.9, label_source=source)
>>> eagle_bb = Rectangle(x1=0.2, y1=0.2, x2=0.8, y2=0.8)
>>> eagle_scored_label = ScoredLabel(label=eagle_label, probability=0.6, label_source=source)
>>> annotation_scene = AnnotationSceneEntity(
         annotations=[
             Annotation(shape=falcon_bb, labels=[falcon_scored_label]),
             Annotation(shape=eagle_bb, labels=[eagle_scored_label]),
         ], kind=AnnotationSceneKind.PREDICTION
     )
>>> ResultMediaEntity(
        name="Model Predictions",
        type="Bounding Box Annotations",
        annotation_scene=annotation_scene,
        numpy=image_array
    )
Parameters:
  • name (str) – Name.

  • type (str) – The type of data (e.g. Attention map). This type is descriptive.

  • annotation_scene (AnnotationScene Entity) – Associated annotation which was generated by the task alongside this media.

  • numpy (np.ndarray) – The data as a numpy array.

  • roi (Optional[Annotation]) – The ROI covered by this media. If null, assume the entire image. Defaults to None.

  • label (Optional[LabelEntity]) – A label associated with this media. Defaults to None.

property height: int#

Returns the height of the result media.

property numpy: ndarray#

Returns the data.

property width: int#

Returns the width of the result media.