otx.api.usecases.exportable_code.prediction_to_annotation_converter#

Converters for output of inferencers.

Functions

convert_bbox_to_ellipse(x1, y1, x2, y2)

Convert bbox to ellipse.

create_converter(converter_type, labels[, ...])

Simple factory for converters based on type of tasks.

Classes

AnomalyClassificationToAnnotationConverter(...)

Converts AnomalyClassification Predictions ModelAPI to Annotations.

AnomalyDetectionToAnnotationConverter(...)

Converts Anomaly Detection Predictions ModelAPI to Annotations.

AnomalySegmentationToAnnotationConverter(...)

Converts AnomalyClassification Predictions ModelAPI to Annotations.

ClassificationToAnnotationConverter(label_schema)

Converts Classification Predictions ModelAPI to Annotations.

DetectionBoxToAnnotationConverter(labels)

Converts DetectionBox Predictions ModelAPI to Annotations.

DetectionToAnnotationConverter(labels[, ...])

Converts Object Detections to Annotations.

IPredictionToAnnotationConverter()

Interface for converter.

MaskToAnnotationConverter(labels[, ...])

Converts DetectionBox Predictions ModelAPI to Annotations.

RotatedRectToAnnotationConverter(labels[, ...])

Converts Rotated Rect (mask) Predictions ModelAPI to Annotations.

SegmentationToAnnotationConverter(label_schema)

Converts Segmentation Predictions ModelAPI to Annotations.

VisualPromptingToAnnotationConverter()

Converts Visual Prompting Predictions ModelAPI to Annotations.

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.AnomalyClassificationToAnnotationConverter(label_schema: LabelSchemaEntity)[source]#

Bases: IPredictionToAnnotationConverter

Converts AnomalyClassification Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(predictions: AnomalyResult, metadata: Dict[str, Any]) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.AnomalyDetectionToAnnotationConverter(label_schema: LabelSchemaEntity)[source]#

Bases: IPredictionToAnnotationConverter

Converts Anomaly Detection Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

Initialize AnomalyDetectionToAnnotationConverter.

Parameters:

label_schema (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(predictions: AnomalyResult, metadata: Dict[str, Any]) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.AnomalySegmentationToAnnotationConverter(label_schema: LabelSchemaEntity)[source]#

Bases: IPredictionToAnnotationConverter

Converts AnomalyClassification Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(predictions: AnomalyResult, metadata: Dict[str, Any]) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (AnomalyResult) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.ClassificationToAnnotationConverter(label_schema: LabelSchemaEntity, hierarchical_cls_heads_info: Dict | None = None)[source]#

Bases: IPredictionToAnnotationConverter

Converts Classification Predictions ModelAPI to Annotations.

Parameters:
  • labels (LabelSchemaEntity) – Label Schema containing the label info of the task

  • hierarchical_cls_heads_info (Dict) – Info from model.hierarchical_info[“cls_heads_info”]

convert_to_annotation(predictions: ClassificationResult, metadata: Dict | None = None) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.DetectionBoxToAnnotationConverter(labels: LabelSchemaEntity)[source]#

Bases: IPredictionToAnnotationConverter

Converts DetectionBox Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(predictions: List[Detection], metadata: Dict[str, Any]) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.DetectionToAnnotationConverter(labels: LabelSchemaEntity | List, configuration: Dict[str, Any] | None = None)[source]#

Bases: IPredictionToAnnotationConverter

Converts Object Detections to Annotations.

Parameters:

labels (List[LabelEntity]) – list of labels

convert_to_annotation(predictions: DetectionResult | ndarray, metadata: Dict[str, ndarray] | None = None) AnnotationSceneEntity[source]#

Convert predictions to annotation format.

Parameters:
  • predictions (DetectionResult|np.ndarray) – detection represented in ModelAPI format or

  • [num_predictions (array with shape) –

    [num_predictions, 7] Supported detection formats are

    • [label, confidence, x1, y1, x2, y2]

    • [_, label, confidence, x1, y1, x2, y2]

    label can be any integer that can be mapped to self.labels confidence should be a value between 0 and 1 x1, x2, y1 and y2 are expected to be normalized.

  • or (6]) –

    [num_predictions, 7] Supported detection formats are

    • [label, confidence, x1, y1, x2, y2]

    • [_, label, confidence, x1, y1, x2, y2]

    label can be any integer that can be mapped to self.labels confidence should be a value between 0 and 1 x1, x2, y1 and y2 are expected to be normalized.

  • metadata (Optional[Dict]) – Additional information

Returns:

AnnotationScene Object containing the boxes obtained from the prediction.

Return type:

AnnotationScene

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.IPredictionToAnnotationConverter[source]#

Bases: object

Interface for converter.

abstract convert_to_annotation(predictions: Any, metadata: Dict) AnnotationSceneEntity[source]#

Convert raw predictions to AnnotationScene format.

Parameters:
  • predictions (Any) – raw predictions from inferencer

  • metadata (Dict) – metadata from inferencer

Returns:

annotation object containing the shapes obtained from the raw predictions.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.MaskToAnnotationConverter(labels: LabelSchemaEntity, configuration: Dict[str, Any] | None = None)[source]#

Bases: IPredictionToAnnotationConverter

Converts DetectionBox Predictions ModelAPI to Annotations.

convert_to_annotation(predictions: InstanceSegmentationResult, metadata: Dict[str, Any]) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.RotatedRectToAnnotationConverter(labels: LabelSchemaEntity, configuration: Dict[str, Any] | None = None)[source]#

Bases: IPredictionToAnnotationConverter

Converts Rotated Rect (mask) Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(predictions: InstanceSegmentationResult, metadata: Dict[str, Any]) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.SegmentationToAnnotationConverter(label_schema: LabelSchemaEntity)[source]#

Bases: IPredictionToAnnotationConverter

Converts Segmentation Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(predictions: ImageResultWithSoftPrediction, metadata: Dict[str, Any] | None = None) AnnotationSceneEntity[source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • predictions (tuple) – Raw predictions from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

class otx.api.usecases.exportable_code.prediction_to_annotation_converter.VisualPromptingToAnnotationConverter[source]#

Bases: IPredictionToAnnotationConverter

Converts Visual Prompting Predictions ModelAPI to Annotations.

Parameters:

labels (LabelSchemaEntity) – Label Schema containing the label info of the task

convert_to_annotation(hard_prediction: ndarray, metadata: Dict[str, Any]) List[Annotation][source]#

Convert predictions to OTX Annotation Scene using the metadata.

Parameters:
  • hard_prediction (np.ndarray) – Hard_prediction from the model.

  • metadata (Dict[str, Any]) – Variable containing metadata information.

Returns:

OTX annotation scene entity object.

Return type:

AnnotationSceneEntity

otx.api.usecases.exportable_code.prediction_to_annotation_converter.convert_bbox_to_ellipse(x1, y1, x2, y2) Ellipse[source]#

Convert bbox to ellipse.

otx.api.usecases.exportable_code.prediction_to_annotation_converter.create_converter(converter_type: Domain, labels: LabelSchemaEntity, configuration: Dict[str, Any] | None = None) IPredictionToAnnotationConverter[source]#

Simple factory for converters based on type of tasks.

Parameters: