General#

This module define the annotation entity.

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

Base class for annotation objects.

Args:

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#

Appends the scored label to the annotation.

Args:

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

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

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

Args:

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]#

Get scored labels that are assigned to this annotation.

Args:

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

Returns:

List of labels in annotation

property id#

DEPRECATED.

property id_#

Returns the id for the annotation.

set_labels(labels: List[ScoredLabel]) None#

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

Args:

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

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: Optional[datetime] = None, id: Optional[ID] = None)#

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)
Args:

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.

property annotations: List[Annotation]#

Return the Annotations that are present in the AnnotationSceneEntity.

append_annotation(annotation: Annotation) None#

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

append_annotations(annotations: List[Annotation]) None#

Adds a list of annotations to the annotation scene.

contains_any(labels: List[LabelEntity]) bool#

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

Args:

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

Returns:

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

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.

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

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

Args:

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

Returns:

Set[ID]: a set of the ID’s of labels which appear in this annotation.

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

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

Args:

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

Returns:

List[LabelEntity]: a list of labels which appear in this annotation.

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)#

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#

Represents ‘AnnotationSceneEntity not found.

This module define the color entity.

class otx.api.entities.color.Color(red: int, green: int, blue: int, alpha: int = 255)#

Represents an RGBA color.

property bgr_tuple: Tuple[int, int, int]#

Retrieves the Color as a BGR tuple.

Returns:

Tuple[int, int, int]

classmethod from_hex_str(string: str) Color#

Creates Color() instance given a hex string.

Supports 6 character hex string (RGB), or 8 character hex string (RGBA). The string might optionally start with a number sign (#).

Example:

Creating color object:

>>> Color.from_hex_str("#ff0000")
Color(red=255, green=0, blue=0, alpha=255)
>>> Color.from_hex_str("0000ff")
Color(red=0, green=0, blue=255, alpha=255)
>>> Color.from_hex_str("#96Ff00C8")
Color(red=150, green=255, blue=0, alpha=200)
Args:

string (str): Hex string

Returns:

Color instance

property hex_str: str#

Returns the color in a Hex representation.

classmethod random() Color#

Generate random Color() instance.

Returns:

Color instance with random color

property rgb_tuple: Tuple[int, int, int]#

Retrieves the Color as a RGB tuple.

Returns:

Tuple[int, int, int]

class otx.api.entities.color.ColorEntity(red: int, green: int, blue: int, alpha: int)#

This class represents an abstract Color, some functions are still abstract.

property alpha: int#

Returns the alpha value for the ColorEntity object.

property blue: int#

Returns the blue color value for the ColorEntity object.

abstract classmethod from_hex_str(string: str)#

Converts a hex string to a color.

Args:

string (str): The hex string

property green: int#

Returns the green color value for the ColorEntity object.

abstract property hex_str: str#

Returns the color in a Hex representation.

abstract classmethod random()#

Generates a random Color.

property red: int#

Returns the red color value for the ColorEntity object.

This module implements the Coordinate entity.

class otx.api.entities.coordinate.Coordinate(x: float, y: float)#

Represents a 2D-coordinate with an x-position and a y-position.

NB most coordinates are normalized (between 0.0 and 1.0)

Args:

x (float): x-coordinate y (float): y-coordinate

as_int_tuple() Tuple[int, int]#

Convert the coordinates to a pair of integer coordinates (x,y).

as_tuple() Tuple[float, float]#

Convert the coordinates to a pair (x,y).

x#
y#

This module implements the dataset item entity.

class otx.api.entities.dataset_item.DatasetItemEntity(media: IMedia2DEntity, annotation_scene: AnnotationSceneEntity, roi: Optional[Annotation] = None, metadata: Optional[List[MetadataItemEntity]] = None, subset: Subset = Subset.NONE, ignored_labels: Optional[Union[List[LabelEntity], Tuple[LabelEntity, ...], Set[LabelEntity]]] = None)#

DatasetItemEntity represents an item in the DatasetEntity.

It holds a media item, annotation and an ROI. The ROI determines the region of interest for the dataset item, and is described by a shape entity.

The fundamental properties of a dataset item are:

  • A 2d media entity (e.g. Image)

  • A 2d annotation entity for the full resolution media entity

  • An ROI, describing the region of interest.

  • The subset it belongs to

  • Metadata for the media entity (e.g. saliency map or active score)

  • A list of labels to ignore

Getting data from dataset item

The first step is to fetch the input data for the network.

>>> dataset_item = DatasetItemEntity()
>>> media_numpy = dataset_item.numpy  # RGB media data (Height, Width, Channels)

This returns the numpy data for the assigned ROI. But it is possible to extract any arbitrary region.

>>> from otx.api.entities.shapes.rectangle import Rectangle
>>> top_left_quart_roi = Annotation(Rectangle(x1=0.0, y1=0.0, x2=0.5, y2=0.5), labels=[])
>>> top_left_quart_numpy = dataset_item.roi_numpy(roi=top_left_quart_roi)

Get the subset of labels for the item ROI:

>>> labels = dataset_item.get_roi_labels(labels=...)

Get the annotations __visible__ in the ROI:

>>> dataset_item.get_annotations()

Adding output data to dataset item

It is possible to add shapes or just labels for the ROI.

Add shapes to dataset item:

>>> box = Rectangle(x1=0.2, y1=0.3, x2=0.6, y2=0.5)
>>> dataset_item.append_annotations(annotations=[Annotation(box, labels=[...])])

Add labels to ROI:

>>> dataset_item.append_labels(labels=[...])
Args:

media (IMedia2DEntity): Media item annotation_scene (AnnotationSceneEntity): Annotation scene roi (Optional[Annotation]): Region Of Interest metadata (Optional[List[MetadataItemEntity]]): Metadata attached to dataset item subset (Subset): Subset for item. E.g. Subset.VALIDATION ignored_labels (Optional[Union[List[LabelEntity], Tuple[LabelEntity, …], Set[LabelEntity]]]): Collection of

labels that should be ignored in this dataset item. For instance, in a training scenario, this parameter is used to ignore certain labels within the existing annotations because their status becomes uncertain following a label schema change.

property annotation_scene: AnnotationSceneEntity#

Access to annotation scene.

append_annotations(annotations: Sequence[Annotation])#

Adds a list of shapes to the annotation.

append_labels(labels: List[ScoredLabel])#

Appends labels to the DatasetItem and adds it to the the annotation label as well if it’s not yet there.

Args:

labels (List[ScoredLabel]): list of labels to be appended.

append_metadata_item(data: IMetadata, model: Optional[ModelEntity] = None)#

Appends metadata produced by some model to the dataset item.

Adding visualization heatmap (ResultMediaEntity) to DatasetItemEntity

>>> from otx.api.entities.image import Image
>>> from otx.api.entities.result_media import ResultMediaEntity
>>> media = Image(file_path='image.jpeg')
>>> annotation = NullAnnotationSceneEntity()
>>> dataset_item = DatasetItem(media=media, annotation_scene=annotation)
>>> data = np.ones((120, 120, 3)).astype(np.uint8) * 255 # Saliency numpy
>>> result_media = ResultMediaEntity(name="Gradcam++",
...                                  type="Gradcam++",
...                                  annotation_scene=annotation,
...                                  numpy=data)
>>> dataset_item.append_metadata_item(result_media)

Representation vector for active learning

>>> from otx.api.entities.tensor import TensorEntity
>>> tensor = TensorEntity(name="representation_vector", numpy=data)
>>> dataset_item.append_metadata_item(data=tensor, model=model)
Args:

data (IMetadata): any object of a class inherited from IMetadata. (e.g., FloatMetadata, Tensor) model (Optional[ModelEntity]): model that was used to generated metadata

get_annotations(labels: Optional[List[LabelEntity]] = None, include_empty: bool = False, include_ignored: bool = False) List[Annotation]#

Returns a list of annotations that exist in the dataset item (wrt. ROI).

This is done by checking that the center of the annotation is located in the ROI.

Args:
labels (Optional[LabelEntity]): Subset of input labels to filter with; if None, all the shapes within

the ROI are returned.

include_empty (bool): if True, returns both empty and non-empty labels include_ignored (bool): if True, includes the labels in ignored_labels

Returns:

List[Annotation]: The intersection of the input label set and those present within the ROI

get_metadata() List[MetadataItemEntity]#

Returns the metadata.

get_metadata_by_name_and_model(name: str, model: Optional[ModelEntity]) Sequence[MetadataItemEntity]#

Returns a metadata item with name and generated by model.

Args:

name (str): the name of the metadata model (Optional[ModelEntity]): the model which was used to generate the metadata.

Returns:

Sequence[MetadataItemEntity]: a list of metadata items with name and generated by model.

get_roi_labels(labels: Optional[List[LabelEntity]] = None, include_empty: bool = False, include_ignored: bool = False) List[LabelEntity]#

Return the subset of the input labels which exist in the dataset item (wrt. ROI).

Args:
labels (Optional[List[LabelEntity]]): Subset of input labels to filter with; if None, all the labels

within the ROI are returned.

include_empty (bool): if True, returns both empty and non-empty labels include_ignored (bool): if True, includes the labels in ignored_labels

Return:

List[LabelEntity]: The intersection of the input label set and those present within the ROI.

get_shapes_labels(labels: Optional[List[LabelEntity]] = None, include_empty: bool = False, include_ignored: bool = False) List[LabelEntity]#

Get the labels of the shapes present in this dataset item.

if a label list is supplied, only labels present within that list are returned. if include_empty is True, present empty labels are returned as well.

Args:
labels (Optional[List[LabelEntity]]): if supplied only labels present in this list are returned.

Defaults to None.

include_empty (bool): if True, returns both empty and non-empty labels. Defaults to False. include_ignored (bool): if True, includes the labels in ignored_labels. Defaults to False.

Returns:

List[LabelEntity]: a list of labels from the shapes within the roi of this dataset item

property height: int#

The height of the dataset item, taking into account the ROI.

property ignored_labels: Set[LabelEntity]#

Get the IDs of the labels to ignore in this dataset item.

property media: IMedia2DEntity#

Media.

property numpy: ndarray#

Returns the numpy data for the media, taking ROI into account.

Returns:

np.ndarrray: Numpy array. RGB array of shape (Height, Width, Channels)

property roi: Annotation#

Region Of Interest.

roi_numpy(roi: Optional[Annotation] = None) ndarray#

Gives the numpy data for the media, given an ROI.

This function allows to take a crop of any arbitrary region of the media in the Dataset entity. If the ROI is not given, the ROI assigned to the DatasetItem will be used as default.

Args:

roi (Optional[Annotation]): Shape entity. The shape will be converted if needed, to extract the ROI numpy.

Returns:

np.ndarray: Numpy array with media data

set_metadata(metadata: List[MetadataItemEntity])#

Sets the metadata.

property subset: Subset#

Returns the subset that the IDatasetItem belongs to. e.g. Subset.TRAINING.

property width: int#

The width of the dataset item, taking into account the ROI.

This module implements the Dataset entity.

class otx.api.entities.datasets.DatasetEntity(items: Optional[List[DatasetItemEntity]] = None, purpose: DatasetPurpose = DatasetPurpose.INFERENCE)#

A dataset consists of a list of DatasetItemEntities and a purpose.

## With dataset items

This way assumes the dataset item entities are constructed before the dataset entity is made.

>>> from otx.api.entities.image import Image
>>> from otx.api.entities.annotation import NullAnnotationSceneEntity
>>> from otx.api.entities.dataset_item import DatasetItemEntity
>>> item = DatasetItemEntity(media=Image(file_path="image.jpg"), annotation_scene=NullAnnotationSceneEntity())
>>> dataset = DatasetEntity(items=[item])

## Iterate over dataset

Regardless of the instantiation method chosen, the Dataset will work the same. The dataset can be iterated:

>>> dataset = DatasetEntity(items=[item_1])
>>> for dataset_item in dataset:
...     print(dataset_item)
DatasetItemEntity(
    media=Image(image.jpg, width=640, height=480),
    annotation_scene=NullAnnotationSceneEntity(),
    roi=Annotation(
        shape=Rectangle(
            x=0.0,
            y=0.0,
            width=1.0,
            height=1.0
            ),
            labels=[],
            id=6149e454893b7ebbe3a8faf6
        ),
    subset=NONE
)

A particular item can also be fetched:

>>> first_item = dataset[0]

Or a slice:

>>> first_ten = dataset[:10]
>>> last_ten = dataset[-10:]

## Get a subset of Dataset

To get the test data for validating the network:

>>> dataset = DatasetEntity()
>>> testing_subset = dataset.get_subset(Subset.TESTING)

This subset is also a DatasetEntity. The entities in the subset dataset refer to the same entities as in the original dataset. Altering one of the objects in the subset, will also alter them in the original.

Args:

items (Optional[List[DatasetItemEntity]]): A list of dataset items to create dataset with. Defaults to None. purpose (DatasetPurpose): Purpose for dataset. Refer to DatasetPurpose for more info.

Defaults to DatasetPurpose.INFERENCE.

append(item: DatasetItemEntity) None#

Append a DatasetItemEntity to the dataset.

Example:

Appending a dataset item to a dataset

>>> from otx.api.entities.image import Image
>>> from otx.api.entities.annotation import NullAnnotationSceneEntity
>>> from otx.api.entities.dataset_item import DatasetItemEntity
>>> dataset = DatasetEntity()
>>> media = Image(file_path='image.jpg')
>>> annotation = NullAnnotationSceneEntity()
>>> dataset_item = DatasetItemEntity(media=media, annotation_scene=annotation)
>>> dataset.append(dataset_item)
Args:

item (DatasetItemEntity): item to append

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

Returns the list of all unique labels that are in the dataset.

Note: This does not respect the ROI of the dataset items.

Args:

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

Returns:

List[LabelEntity]: list of labels that appear in the dataset

get_subset(subset: Subset) DatasetEntity#

Returns a new DatasetEntity with just the dataset items matching the subset.

This subset is also a DatasetEntity. The dataset items in the subset dataset are the same dataset items as in the original dataset. Altering one of the objects in the output of this function, will also alter them in the original.

Example:
>>> dataset = DatasetEntity()
>>> training_subset = dataset.get_subset(Subset.TRAINING)
Args:

subset (Subset): Subset to return.

Returns:

DatasetEntity: DatasetEntity with items matching subset

property purpose: DatasetPurpose#

Returns the DatasetPurpose. For example DatasetPurpose.ANALYSIS.

Returns:

DatasetPurpose

remove(item: DatasetItemEntity) None#

Remove an item from the items.

This function calls remove_at_indices function.

Args:

item (DatasetItemEntity): the item to be deleted.

Raises:

ValueError: if the input item is not in the dataset

remove_at_indices(indices: List[int]) None#

Delete items based on the indices.

Args:

indices (List[int]): the indices of the items that will be deleted from the items.

sort_items() None#

Order the dataset items. Does nothing here, but may be overridden in child classes.

Returns:

None

with_empty_annotations(annotation_kind: AnnotationSceneKind = AnnotationSceneKind.PREDICTION) DatasetEntity#

Produces a new dataset with empty annotation objects (no shapes or labels).

This is a convenience function to generate a dataset with empty annotations from another dataset. This is particularly useful for evaluation on validation data and to build resultsets.

Assume a dataset containing user annotations.

>>> labeled_dataset = Dataset()  # user annotated dataset

Then, we want to see the performance of our task on this labeled_dataset, which means we need to create a new dataset to be passed for analysis.

>>> prediction_dataset = labeled_dataset.with_empty_annotations()

Later, we can pass this prediction_dataset to the task analysis function. By pairing the labeled_dataset and the prediction_dataset, the resultset can then be constructed. Refer to otx.api.entities.resultset.ResultSetEntity for more info.

Args:
annotation_kind (AnnotationSceneKind): Sets the empty annotation to this kind.

Defaults to AnnotationSceneKind.PREDICTION

Returns:

DatasetEntity: a new dataset containing the same items, with empty annotation objects.

class otx.api.entities.datasets.DatasetIterator(dataset: DatasetEntity)#

This DatasetIterator iterates over the dataset lazily.

Implements collections.abc.Iterator.

Args:

dataset (DatasetEntity): Dataset to iterate over.

class otx.api.entities.datasets.DatasetPurpose(value)#

Describes the purpose for the dataset.

This makes it possible to identify datasets for a particular use.

EVALUATION = 2#
GENERATING_OUTPUT = 3#
INFERENCE = 0#
TASK_INFERENCE = 5#
TEMPORARY_DATASET = 4#
TRAINING = 1#

This module implements the TrainParameters entity.

class otx.api.entities.graph.Graph(directed: bool = False)#

The concrete implementation of IGraph. This implementation is using networkx library.

Args:

directed (bool): set to True if the graph is a directed graph.

add_edge(node1, node2, edge_value=None)#

Adds edge between node1 and node2.

add_node(node)#

Adds node to the graph.

descendants(parent)#

Returns descendants.

(children and children of children, etc.) of parent.

property edges#

Returns all the edges in the graph.

find_cliques()#

Returns cliques in the graph.

find_in_edges(node)#

Returns the edges that have node as a source.

find_out_edges(node)#

Returns the edges that have node as a destination.

get_graph() Union[Graph, MultiDiGraph]#

Get the underlying NetworkX graph.

has_edge_between(node1, node2)#

Returns True if there is an edge between node1 and node2.

neighbors(node)#

Returns neighbors of label.

Note: when node does not exist in the graph an empty list is returned

property nodes#

Returns the nodes in the graph.

property num_labels#

Returns the number of labels in the graph.

num_nodes() int#

Returns the number of nodes in the graph.

remove_edges(node1, node2)#

Removes edges between both the nodes.

remove_node(node)#

Remove node from graph.

Args:

node: node to remove

set_graph(graph: Union[Graph, MultiDiGraph])#

Set the underlying NetworkX graph.

class otx.api.entities.graph.MultiDiGraph#

Multi Dimensional implementation of a Graph.

topological_sort()#

Returns a generator of nodes in topologically sorted order.

This module implements the ID entity.

class otx.api.entities.id.ID(representation: Optional[Union[str, ObjectId]] = None)#

An identifier for objects that can be persisted in repositories.

Usually the creation of IDs is handled by the repositories. In that case objects are initialized with an empty ID()
>>> str(ID())
''
Args:

Optional[Union[str, ObjectId]]: value of the identifier

property representation#

Returns the value of the identifier.

This module implements the Image entity.

class otx.api.entities.image.Image(data: Optional[ndarray] = None, file_path: Optional[str] = None)#

Represents a 2D image.

The image must be instantiated with either a NumPy array containing the image data or a path to an image file.

Args:

data (Optional[np.ndarray]): NumPy data. file_path (Optional[str]): Path to image file.

property height: int#

Returns the height of the image.

property numpy: ndarray#

Numpy representation of the image.

For color images the dimensions are (height, width, color) with RGB color channel order.

Returns:

np.ndarray: NumPy representation of the image.

property path: Optional[str]#

Returns the file path of the image.

roi_numpy(roi: Optional[Annotation] = None) ndarray#

Obtains the numpy representation of the image for a selection region of interest (roi).

Args:
roi (Optional[Annotaiton]): The region of interest can be Rectangle in the relative

coordinate system of the full-annotation.

Returns:

np.ndarray: Selected region as numpy array.

property width: int#

Returns the width of the image.

This module implements the AnalyseParameters entity.

class otx.api.entities.inference_parameters.InferenceParameters(is_evaluation: bool = False, update_progress: ~typing.Callable[[int, ~typing.Optional[float]], ~typing.Any] = <function default_progress_callback>, explainer: str = '', process_saliency_maps: bool = False, explain_predicted_classes: bool = True)#

Inference parameters.

Attributes:
is_evaluation: Set to True if the output dataset is intended

to be used for evaluation purposes. In this scenario, any postprocessing filtering (such as thresholding and NMS) should be disabled to avoid interfering with algorithms such as NMS.

update_progress: Callback which can be used to provide updates

about the progress of a task.

explainer: Explain algorithm to be used in explanation mode.

Will be converted automatically to lowercase.

process_saliency_maps: Process saliency map to input image resolution and apply colormap explain_predicted_classes: If set to True, provide explanations only for predicted classes.

Otherwise, explain all classes.

explain_predicted_classes: bool = True#
explainer: str = ''#
is_evaluation: bool = False#
process_saliency_maps: bool = False#
update_progress(score: Optional[float] = None)#

This is the default progress callback for OptimizationParameters.

otx.api.entities.inference_parameters.default_progress_callback(progress: int, score: Optional[float] = None)#

This is the default progress callback for OptimizationParameters.

This module implements the LabelSchema entity.

class otx.api.entities.label_schema.LabelGraph(directed: bool)#

Represents connectivity between labels as a graph. For example exclusivity or hierarchy.

Args:
directed (bool): whether the relationships are directed or undirected

(symmetrical)

add_edges(edges)#

Add edges between Labels.

property num_labels#

Returns the number of nodes in the graph.

subgraph(labels: Sequence[LabelEntity]) LabelGraph#

Return the subgraph containing the given labels.

property type#

Returns the type of the LabelGraph.

class otx.api.entities.label_schema.LabelGroup(name: str, labels: Sequence[LabelEntity], group_type: LabelGroupType = LabelGroupType.EXCLUSIVE, id: Optional[ID] = None)#

A label group which has exclusive (multiclass) or contains the empty label.

Non-exclusive (multilabel) relationships are represented by multiple (exclusive) label groups.

The labels have to be from one task.

Args:

name (str): Descriptive name of the label group labels (Sequence[LabelEntity]): Labels that form the group group_type (LabelGroupType): EXCLUSIVE or EMPTY_LABEL id (ID): ID of the LabelGroup. If no ID is provided, a new ObjectId()

will be assigned

property id: ID#

DEPRECATED.

is_single_label() bool#

Returns True if the label group only contains one label.

Returns:

bool: True if the label group only contains one label.

property minimum_label_id: ID#

Returns the minimum (oldest) label ID, which is the first label in self.labels since this list is sorted.

remove_label(label: LabelEntity) None#

Remove label from label group if it exists in the group.

Args:

label (LabelEntity): label to remove

exception otx.api.entities.label_schema.LabelGroupDoesNotExistException#

Exception thrown if the LabelGroup does not exist.

exception otx.api.entities.label_schema.LabelGroupExistsException#

Exception thrown if the LabelGroup already exists.

class otx.api.entities.label_schema.LabelGroupType(value)#

Enum to indicate the LabelGroupType.

EMPTY_LABEL = 2#
EXCLUSIVE = 1#
class otx.api.entities.label_schema.LabelSchemaEntity(label_tree: Optional[LabelTree] = None, label_groups: Optional[List[LabelGroup]] = None)#

This class represents the relationships of labels.

This class currently keeps track of the following relationships:

  • parent/child label relationship

  • label group relationships

Args:

label_tree (LabelTree): a hierarchy of labels represented as a tree label_groups (List[LabelGroup]): list of groups of labels that form logical groups.

E.g. a group of mutually exclusive labels.

add_child(parent: LabelEntity, child: LabelEntity)#

Add a child Label to parent.

add_group(label_group: LabelGroup)#

Adding a group to label schema.

Args:

label_group (LabelGroup): label group to add

Returns:

None

add_labels_to_group_by_group_name(group_name: str, labels: Sequence[LabelEntity])#

Adds labels to group named group_name.

Args:

labels (str): list of Label group_name (Sequence[LabelEntity]): group name

Raises:
LabelGroupDoesNotExistException: This is raised if the group

does not exist

are_exclusive(label1: LabelEntity, label2: LabelEntity) bool#

Returns whether label and label2 are mutually exclusive.

classmethod from_labels(labels: Sequence[LabelEntity]) LabelSchemaEntity#

Create LabelSchemaEntity from a list of exclusive labels.

Args:

labels (Sequence[LabelEntity]): list of labels

Returns:

LabelSchemaEntity from the given labels

get_ancestors(label: LabelEntity) List[LabelEntity]#

Returns ancestors of label, including self.

get_children(parent: LabelEntity) List[LabelEntity]#

Return a list of the children of the passed parent Label.

get_descendants(parent: LabelEntity) List[LabelEntity]#

Returns descendants (children and children of children, etc.) of parent.

get_exclusive_groups() List[LabelGroup]#

Returns exclusive groups in the LabelSchema.

get_group_containing_label(label: LabelEntity) Optional[LabelGroup]#

Returns the label group which contains the label.

Args:

label (LabelEntity): the query label

Returns:

Optional[LabelGroup]: the group containing the label

get_groups(include_empty: bool = False) List[LabelGroup]#

Get the label groups in the label schema.

Args:
include_empty (bool): flag determining whether to include empty

label groups

Returns:

List[LabelGroup]: list of all label groups in the label schema

get_label_group_by_name(group_name: str) Optional[LabelGroup]#

Get the label group by the passed group_name.

Args:

group_name (str): name of the group to get

Returns:

Optional[LabelGroup]

get_label_ids(include_empty: bool) List[ID]#

Returns a list of label ids that are in the LabelSchema.

Args:

include_empty (bool): Include empty label id or not.

Returns:

List[ID]: sorted list of label ids

get_labels(include_empty: bool) List[LabelEntity]#

Get the labels in the label schema.

Args:
include_empty (bool): flag determining whether to include empty

labels

Returns:

List[LabelEntity]: list of all labels in the label schema

get_labels_exclusive_to(label: LabelEntity) List[LabelEntity]#

Returns a list of labels that are exclusive to the passed label.

get_parent(label: LabelEntity) Optional[LabelEntity]#

Returns the parent of label.

Returns:

Optional[LabelEntity]: the parent if it has one otherwise None

get_siblings_in_group(label: LabelEntity) List[LabelEntity]#

Return a list of the ‘siblings’, which are all labels within the same group as a label.

resolve_labels_probabilistic(scored_labels: List[ScoredLabel], selected_labels: Optional[List[LabelEntity]] = None) List[ScoredLabel]#

Resolves hierarchical labels and exclusivity based on a list of ScoredLabels (labels with probability).

The following two steps are taken:

  • selects the most likely label from an exclusive (multiclass) group

  • removes children of “not-most-likely” (non-max) parents in an exclusive group (top-down approach)

The method is intended to post-process the output of probabilistic systems such as predictions coming from machine learning methods to resolve ambiguities and logical impossibilities. When processing (non-probabilistic) user input please use complete_labels instead.

Args:
scored_labels (List[ScoredLabel]): a list of ScoredLabels (labels with

probability)

selected_labels (List[LabelEntity]): if not None, will only consider labels

within selected_labels for resolving. Any other labels which have relations with selected_labels (e.g. parent), but are outside selected_labels are set to a default probability of 1.0

class otx.api.entities.label_schema.LabelTree#

Represents a hierarchy of labels in the form a tree.

The tree is represented by a directed graph

add_child(parent: LabelEntity, child: LabelEntity)#

Add a child Label to parent.

add_edge(node1, node2, edge_value=None)#

Add edge between two nodes in the tree.

Args:

node1: first node node2: second node edge_value: The value of the new edge. Defaults to None.

add_edges(edges)#

Add edges between Labels.

add_node(node)#

Add node to the tree.

clear_topological_cache()#

Clear the internal cache of the list of labels sorted in topological order.

This function should be called if the topology of the graph has changed to

prevent the cache from being stale.

Note that it is automatically called when modifying the topology through the

methods provided by this class.

get_ancestors(label: LabelEntity) List[LabelEntity]#

Returns ancestors of label, including self.

get_children(parent: LabelEntity) List[LabelEntity]#

Returns children of parent.

get_descendants(parent: LabelEntity) List[LabelEntity]#

Returns descendants (children and children of children, etc.) of parent.

get_labels_in_topological_order() List[LabelEntity]#

Return a list of the labels in this graph sorted in topological order.

To avoid performance issues, the output of this function is cached.

Returns:

List[LabelEntity]: sorted list of labels

get_parent(label: LabelEntity) Optional[LabelEntity]#

Returns the parent of label.

Returns:

the parent if it has one otherwise None

get_siblings(label: LabelEntity) List[LabelEntity]#

Returns the siblings of a label.

property num_labels#

Return the number of labels in the tree.

remove_node(node)#

Remove node from the tree.

subgraph(labels: Sequence[LabelEntity]) LabelTree#

Return the subgraph containing the given labels.

property type#

Returns the type of the LabelTree.

otx.api.entities.label_schema.natural_sort_label_id(target: Union[ID, LabelEntity, ScoredLabel]) List#

Generates a natural sort key for a LabelEntity object based on its ID.

Args: target (Union[ID, LabelEntity]): The ID or LabelEntity or ScoredLabel object to be sorted.

Returns: List[int]: A list of integers representing the numeric substrings in the ID in the order they appear.

Example: origin_sorted_labels = sorted(labels, key=lambda x: x.id_) natural_sorted_labels = sorted(labels, key=lambda x: x.natural_sort_label_id)

print(origin_sorted_labels) # Output: [LabelEntity(0), LabelEntity(1), LabelEntity(10), … LabelEntity(2)] print(natural_sorted_labels) # Output: [LabelEntity(0), LabelEntity(1), LabelEntity(2), … LabelEntity(10)]

This module define the label entity.

class otx.api.entities.label.Domain(value)#

Describes an algorithm domain like classification, detection, etc.

ACTION_CLASSIFICATION = 10#
ACTION_DETECTION = 11#
ANOMALY_CLASSIFICATION = 5#
ANOMALY_DETECTION = 6#
ANOMALY_SEGMENTATION = 7#
CLASSIFICATION = 2#
DETECTION = 3#
INSTANCE_SEGMENTATION = 8#
NULL = 1#
ROTATED_DETECTION = 9#
SEGMENTATION = 4#
class otx.api.entities.label.LabelEntity(name: str, domain: Domain, color: Optional[Color] = None, hotkey: str = '', creation_date: Optional[datetime] = None, is_empty: bool = False, id: Optional[ID] = None, is_anomalous: bool = False)#

This represents a label. The Label is the object that the user annotates and the tasks predict.

For example, a label with name “car” can be constructed as follows.

>>> car = LabelEntity(name="car", domain=Domain.DETECTION)

About Empty Label

In addition to representing the presence of a certain object, the label can also be used to represent the absence of objects in the image (or other media types). Such a label is referred to as empty label. The empty label is constructed as follows:

>>> empty = LabelEntity(name="empty", domain=Domain.DETECTION, is_empty=True)

Empty label is used to declare that there is nothing of interest inside this image. For example, let’s assume a car detection project. During annotation process, for positive images (images with cars), the users are asked to annotate the images with bounding boxes with car label. However, when the user sees a negative image (no car), the user needs to annotate this image with an empty label.

The empty label is particularly useful to distinguish images with no objects of interest from images that have not been annotated, especially in task-chain scenario. Let’s assume car detection task that is followed with with another detection task which detects the driver inside the car. There are two issues here:

  1. The user can (intentionally or unintentionally) miss to annotate

    the driver inside a car.

  2. There is no driver inside the car.

Without empty label, these two cases cannot be distinguished. This is why an empty label is introduced. The empty label makes an explicit distinction between missing annotations and “negative” images.

Args:

name: the name of the label domain: the algorithm domain this label is associated to color: the color of the label (See Color) hotkey: key or combination of keys to select this label in the

UI

creation_date: the date time of the label creation is_empty: set to True if the label is an empty label. id: the ID of the label. Set to ID() so that a new unique ID

will be assigned upon saving. If the argument is None, it will be set to ID()

is_anomalous: boolean that indicates whether the label is the

Anomalous label. Always set to False for non- anomaly projects.

property color: Color#

Returns the Color object for the label.

property creation_date: datetime#

Returns the creation date of the label.

property domain#

Returns the algorithm domain associated to this label.

property hotkey: str#

Returns the hotkey for the label.

property id: ID#

DEPRECATED.

property id_: ID#

Returns the label id.

property is_empty: bool#

Returns a boolean indicating if the label is an empty label.

property name#

Returns the label name.

This module implements the Media entity.

class otx.api.entities.media.IMedia2DEntity#

This interface is used to represent IMedia which is 2-dimensional media, i.e., containing height and width.

abstract property height: int#

Returns the height of the 2D Media object.

abstract property numpy: ndarray#

Returns the numpy representation of the 2D Media object.

property path: Optional[str]#

Returns the path of the 2D Media object.

abstract roi_numpy(roi: Optional[Annotation]) ndarray#

Returns the numpy representation of the 2D Media object while taking the roi into account.

abstract property width: int#

Returns the width representation of the 2D Media object.

class otx.api.entities.media.IMediaEntity#

Media entity interface.

This interface is used to represent any kind of media data, on which users can annotate and tasks can perform training/analysis.

This module defines classes representing metadata information.

class otx.api.entities.metadata.FloatMetadata(name: str, value: float, float_type: FloatType = FloatType.FLOAT)#

This class represents metadata of type float.

Args:

name (str): Name of the metadata. value (float): Value of the metadata. float_type (FloatType): Type of the metadata.

class otx.api.entities.metadata.FloatType(value)#

Represents the use of the FloatMetadata.

ACTIVE_SCORE = 3#
EMBEDDING_VALUE = 2#
FLOAT = 1#
class otx.api.entities.metadata.IMetadata#

This interface represents any additional metadata information which can be connected to an IMedia.

property name#

Gets or sets the name of the Metadata item.

class otx.api.entities.metadata.MetadataItemEntity(data: Any, model: Optional[ModelEntity] = None)#

This class is a wrapper class which connects the metadata value to model, which was used to generate it.

Args:

data (IMetadata): The metadata value. model (Optional[ModelEntity]): The model which was used to generate the metadata. Defaults to None.

class otx.api.entities.metadata.VideoMetadata(video_id: str, frame_idx: int, is_empty_frame: bool)#

This class represents metadata of video.

Args:

video_id (str): id(name) for video. frame_idx (int): Index for frame. is_empty_frame(bool): whether this is empty frame(for action detection)

update(key: str, value: Any)#

Update metadata infomation.

This module implements the Metric entities.

class otx.api.entities.metrics.BarChartInfo(name: str, palette: ColorPalette = ColorPalette.DEFAULT, visualization_type: VisualizationType = VisualizationType.BAR)#

This represents a visualization using a bar chart.

name: str#
class otx.api.entities.metrics.BarMetricsGroup(metrics: Sequence[Union[ScoreMetric, CountMetric]], visualization_info: BarChartInfo)#

This class represent a bar or radial bar chart in the UI.

Each metric in the metrics group represents the value of a single bar/radial bar in the chart.

class otx.api.entities.metrics.ColorPalette(value)#

Enum class specifying the color palette to be used by the UI to display statistics.

If the statistics are per label, set to LABEL so the UI will use the label color palette. Otherwise, set to DEFAULT (allow the UI to choose a color palette)

DEFAULT = 0#
LABEL = 1#
class otx.api.entities.metrics.CountMetric(name: str, value: int)#

This metric represents an integer value.

Args:

name: The name of the metric value: The value of the metric

Example:

The count for number of images in a project

>>> count_metric = CountMetric(name="Number of images", value=20)
static type()#

Returns the type of the MetricEntity.

value: int#
class otx.api.entities.metrics.CurveMetric(name: str, ys: List[float], xs: Optional[List[float]] = None)#

This metric represents a curve. The coordinates are represented as x and y lists.

Example:

A line curve of: [(0,1), (1, 5), (2, 8)]

>>> CurveMetric("Line", xs=[0, 1, 2], ys=[1, 5, 8])
CurveMetric(name=`Line`, ys=(3 values), xs=(3 values))

A curve can also be defined only using the y values. For example, a loss curve of loss values: [0.5, 0.2, 0.1]. The x values will be automatically generated as a 1-based index (1, 2, 3, …)

>>> CurveMetric("Loss", ys=[0.5, 0.2, 0.1])
CurveMetric(name=`Loss`, ys=(3 values), xs=(None values))
Args:

name: The name of the curve xs: the list of floats in x-axis ys: the list of floats in y-axis

static type()#

Returns the type of the MetricEntity.

property xs: List[float]#

Returns the list of floats on x-axis.

property ys: List[float]#

Returns the list of floats on y-axis.

class otx.api.entities.metrics.DateMetric(name: str, date: Optional[datetime] = None)#

This metric represents a date time value.

Args:

name: The name of the date metric date: The datetime value of the metric

Example:

A DateMetric for model creation date (e.g., now).

>>> metric = DateMetric(name="Model creation", date=datetime.datetime.now(datetime.timezone.utc))
date: datetime#
static type()#

Returns the type of the MetricEntity.

class otx.api.entities.metrics.DurationMetric(name: str, hour: int, minute: int, second: float)#

This metric represents a duration metric, which include hour (int), minute (int), and second (float).

Args:

name: The name of the duration metric hour: The hour value of the metric minute: The minute value of the metric second: The second value of the metric

Example:

Creating a metric for training duration of 1 hour 5 minutes.

>>> duration_metric = DurationMetric(name="Training duration", hour=1, minute=5, second=0)
static from_seconds(name: str, seconds: float) DurationMetric#

Returns a duration metrics, with name and converted durations from seconds.

Example:

Converting 70 seconds to duration metric.

>>> from otx.api.entities.metrics import DurationMetric
>>> dur_met = DurationMetric.from_seconds("test", 70)  # 1 hour 1 minute and 1.5 seconds
>>> dur_met.get_duration_string()
'1 minute 10.00 seconds'
Args:

name seconds

Returns:

DurationMetric: the duration metric with name and converted durations from seconds.

get_duration_string() str#

Returns the string representation of the duration.

Example:

Duration string of 1 hour 1 minute and 1.50 seconds.

>>> from otx.api.entities.metrics import DurationMetric
>>> dur_met = DurationMetric("test", 1, 1, 1.5)  # 1 hour 1 minute and 1.5 seconds
>>> dur_met.get_duration_string()
'1 hour 1 minute 1.50 seconds'
Returns:

the string representation of the duration.

static type()#

Returns the type of the MetricEntity.

class otx.api.entities.metrics.InfoMetric(name: str, value: str)#

This metric represents a string value.

Args:

name: The name of the info metric value: The info of the metric

Example:

An info metric of training from scratch

>>> info_metric = InfoMetric(name="Model info", value="This model is trained from scratch")
static type()#

Returns the type of the MetricEntity.

value: str#
class otx.api.entities.metrics.LineChartInfo(name: str, x_axis_label: Optional[str] = None, y_axis_label: Optional[str] = None, palette: ColorPalette = ColorPalette.DEFAULT)#

This represents a visualization using a line chart.

x_axis_label: str#
y_axis_label: str#
class otx.api.entities.metrics.LineMetricsGroup(metrics: Sequence[CurveMetric], visualization_info: LineChartInfo)#

This class represent a line chart in the UI.

Multiple lines can be displayed in a single chart.

class otx.api.entities.metrics.MatrixChartInfo(name: str, header: Optional[str] = None, row_header: Optional[str] = None, column_header: Optional[str] = None, palette: ColorPalette = ColorPalette.DEFAULT)#

This represents a visualization using a matrix.

column_header: str#
header: str#
row_header: str#
class otx.api.entities.metrics.MatrixMetric(name: str, matrix_values: ndarray, row_labels: Optional[List[str]] = None, column_labels: Optional[List[str]] = None, normalize: bool = False)#

This metric represents a matrix. The cells are represented as a list of lists of integers.

In the case of a confusion matrix, the rows represent the ground truth items and the columns represent the predicted items.

Example:

A matrix of: [[4,0,1], [0,3,2], [1,2,2]]

>>> MatrixMetric("Confusion Matrix", matrix_values=np.array([[4,0,1], [0,3,2], [1,2,2]]))
MatrixMetric(name=`Confusion Matrix`, matrix_values=(3x3) matrix, row labels=None, column labels=None)
Args:

name: The name of the matrix matrix_values: the matrix data row_labels: labels for the rows column_labels: labels for the columns normalize: set to True to normalize each row of the matrix

property column_labels: Optional[List[str]]#

Returns the column labels.

property matrix_values: ndarray#

Returns the matrix data.

normalize()#

Normalizes the confusion matrix by dividing by the sum of the rows.

property row_labels: Optional[List[str]]#

Returns the row labels.

static type()#

Returns the type of the MetricEntity.

class otx.api.entities.metrics.MatrixMetricsGroup(metrics: Sequence[MatrixMetric], visualization_info: MatrixChartInfo)#

This class represent a matrix chart in the UI.

Multiple matrices can be displayed in the same chart.

class otx.api.entities.metrics.MetricEntity#

This interface represents a metric, which is the smallest building block for the performance statistics.

It only contains the name of the metric. See also MetricsGroup and Performance for the structure of performance statistics.

property name#

Returns the name of the Metric Entity.

static type() str#

Returns the type of the MetricEntity, e.g. “curve.

class otx.api.entities.metrics.MetricsGroup(metrics: Sequence[_Metric], visualization_info: _VisualizationInfo)#

This class aggregates a list of metric entities and defines how this group will be visualized on the UI.

This class is the parent class to the different types of MetricsGroup that each represent a different type of chart in the UI.

Example:
An accuracy as a metrics group
>>> acc = ScoreMetric("Accuracy", 0.5)
>>> visual_info = BarChartInfo("Accuracy", visualization_type=_VisualizationInfo.BAR)  # show as radial bar
>>> metrics_group = BarMetricsGroup([acc], visual_info)
Loss curves as a metrics group
>>> train_loss = CurveMetric("Train loss", xs=[0, 1, 2], ys=[5, 3, 1])
>>> val_loss = CurveMetric("Validation", xs=[0, 1, 2], ys=[6, 4, 2])
>>> visual_info = LineChartInfo("Loss curve", x_axis_label="# epoch", y_axis_label="Loss")
>>> metrics_group = LineMetricsGroup([train_loss, val_loss], visual_info)
class otx.api.entities.metrics.MultiScorePerformance(primary_score: Optional[ScoreMetric] = None, additional_scores: Optional[List[ScoreMetric]] = None, dashboard_metrics: Optional[List[MetricsGroup]] = None)#

This class can be used in tasks where performance is measured by multiple metrics.

Args:

primary_score: The main performance score. additional_metrics: List of additional scores. When no primary

score is provided, the first additional score takes priority as the main project score.

dashboard_metrics: (optional) additional statistics, containing

charts, curves, and other additional info.

property additional_scores: List[ScoreMetric]#

Return the additional score metrics.

property primary_score: Optional[ScoreMetric]#

Return the primary score metric.

class otx.api.entities.metrics.NullMetric#

Represents ‘Metric not found’.

static type()#

Returns the type of the MetricEntity.

class otx.api.entities.metrics.NullPerformance#

This is used to represent ‘Performance not found’.

class otx.api.entities.metrics.Performance(score: ScoreMetric, dashboard_metrics: Optional[List[MetricsGroup]] = None)#

This performance class wraps the statistics of an entity (e.g., Model, Resultset).

Args:
score: the performance score. This will be the point of

comparison between two performances.

dashboard_metrics: (optional) additional statistics, containing

charts, curves, and other additional info.

property score#

Return the score metric.

class otx.api.entities.metrics.ScoreMetric(name: str, value: float)#

This metric represents a float value.

This metric is typically used for storing performance metrics, such as accuracy, f-measure, dice score, etc.

Args:

name: The name of the score value: The value of the score

Example:

Accuracy of a model

>>> score_metric = ScoreMetric(name="Model accuracy", value=0.5)
static type()#

Returns the type of the MetricEntity.

class otx.api.entities.metrics.TextChartInfo(name: str)#

This represents a visualization using text, which uses only a single string.

name: str#
class otx.api.entities.metrics.TextMetricsGroup(metrics: Sequence[Union[ScoreMetric, CountMetric, InfoMetric, DateMetric, DurationMetric]], visualization_info: TextChartInfo)#

This class represent a text chart in the UI.

Text charts contain only one metric, which can be of type CountMetric, ScoreMetric, DateMetric, DurationMetric or InfoMetric.

class otx.api.entities.metrics.VisualizationInfo(name: str, visualisation_type: VisualizationType, palette: ColorPalette = ColorPalette.DEFAULT)#

This represents the visualization info a metrics group. See MetricsGroup.

name: str#
property type: VisualizationType#

Returns the type of the visualization.

class otx.api.entities.metrics.VisualizationType(value)#

This enum defines how the metrics will be visualized on the UI.

BAR = 2#
LINE = 3#
MATRIX = 4#
RADIAL_BAR = 1#
TEXT = 0#

This file defines the ModelConfiguration, ModelEntity and Model classes.

class otx.api.entities.model_template.DatasetRequirements(classes: Optional[List[str]] = None)#

Expected requirements for the dataset in order to use this algorithm.

Attributes:

classes (Optional[List[str]]): Classes which must be present in the dataset

classes: Optional[List[str]] = None#
class otx.api.entities.model_template.Dependency(source: str, destination: str, size: Optional[int] = None, sha256: Optional[str] = None)#

Dependency required by the task.

Attributes:

source (str): Source of the dependency destination (str): Destination folder to install the dependency size (Optional[int]): Size of the dependency in bytes sha256 (Optional[str]): SHA-256 checksum of the dependency file

destination: str#
sha256: Optional[str] = None#
size: Optional[int] = None#
source: str#
class otx.api.entities.model_template.EntryPoints(base: str, openvino: Optional[str] = None, nncf: Optional[str] = None)#

Path of the Python classes implementing the task interface.

Attributes:

base (str): Base interface implementing the functionality in a framework such as PyTorch or TensorFlow openvino (Optional[str]): OpenVINO interface. nncf (Optional[str]): NNCF interface

base: str#
nncf: Optional[str] = None#
openvino: Optional[str] = None#
class otx.api.entities.model_template.ExportableCodePaths(default: Optional[str] = None, openvino: Optional[str] = None)#

The paths to the different versions of the exportable code for a given model template.

default: Optional[str] = None#
openvino: Optional[str] = None#
class otx.api.entities.model_template.HyperParameterData(base_path: ~typing.Optional[str] = None, parameter_overrides: ~typing.Dict = <factory>, _HyperParameterData__data: ~typing.Dict = <factory>, _HyperParameterData__has_valid_configurable_parameters: bool = False)#

HyperParameter Data.

Class that contains the raw hyper parameter data, for those hyper parameters for the model that are user-configurable.

Attributes:
base_path (Optional[str]): The path to the yaml file specifying the base configurable parameters to use in the

model. Defaults to None.

parameter_overrides (Dict): Nested dictionary that describes overrides for the metadata for the

user-configurable hyper parameters that are used in the model. This allows multiple models to share the same base hyper-parameters, while for each individual model the defaults, parameter ranges, descriptions, etc. can still be customized.

base_path: Optional[str] = None#
property data: Dict#

Returns a dictionary containing the set of hyper parameters defined in the ModelTemplate.

This does not contain the actual parameter values, but instead holds the parameter schema’s in a structured manner. The actual values should be either loaded from the database, or will be initialized from the defaults upon creating a configurable parameter object out of this data.

property has_overrides: bool#

Returns True if any parameter overrides are defined by the HyperParameters instance, False otherwise.

property has_valid_configurable_parameters: bool#

Check if configurable parameters are valid.

Returns True if the HyperParameterData instance contains valid configurable parameters, extracted from the model template. False otherwise.

load_parameters(model_template_path: str)#

Load hyper parameters.

Loads the actual hyper parameters defined in the file at base_path, and performs any overrides specified in the parameter_overrides.

Args:

model_template_path (str): file path to the model template file in which the HyperParameters live.

manually_set_data_and_validate(hyper_parameters: dict)#

This function is used to manually set the hyper parameter data from a dictionary.

It is meant to be used in testing only, in cases where the model template is not backed up by an actual yaml file.

Args:

hyper_parameters (Dict): Dictionary containing the data to be set

parameter_overrides: Dict#
substitute_parameter_overrides()#

Carries out the parameter overrides specified in the parameter_overrides attribute.

Validates whether the overridden parameters exist in the base set of configurable parameters, and whether the metadata values that should be overridden are valid metadata attributes.

class otx.api.entities.model_template.InstantiationType(value)#

The method to instantiate a given task.

CLASS = 2#
GRPC = 3#
NONE = 1#
class otx.api.entities.model_template.ModelOptimizationMethod(value)#

Optimized model format.

OPENVINO = 2#
TENSORRT = 1#
class otx.api.entities.model_template.ModelTemplate(model_template_id: str, model_template_path: str, name: str, task_family: ~otx.api.entities.model_template.TaskFamily, task_type: ~otx.api.entities.model_template.TaskType, instantiation: ~otx.api.entities.model_template.InstantiationType, summary: str = '', framework: ~typing.Optional[str] = None, max_nodes: int = 1, application: ~typing.Optional[str] = None, dependencies: ~typing.List[~otx.api.entities.model_template.Dependency] = <factory>, initial_weights: ~typing.Optional[str] = None, training_targets: ~typing.List[~otx.api.entities.model_template.TargetDevice] = <factory>, inference_targets: ~typing.List[~otx.api.entities.model_template.TargetDevice] = <factory>, dataset_requirements: ~otx.api.entities.model_template.DatasetRequirements = <factory>, model_optimization_methods: ~typing.List[~otx.api.entities.model_template.ModelOptimizationMethod] = <factory>, hyper_parameters: ~otx.api.entities.model_template.HyperParameterData = <factory>, is_trainable: bool = True, capabilities: ~typing.List[str] = <factory>, grpc_address: ~typing.Optional[str] = None, entrypoints: ~typing.Optional[~otx.api.entities.model_template.EntryPoints] = None, base_model_path: str = '', exportable_code_paths: ~otx.api.entities.model_template.ExportableCodePaths = <factory>, task_type_sort_priority: int = -1, gigaflops: float = 0, size: float = 0, hpo: ~typing.Optional[~typing.Dict] = None)#

This class represents a Task in the Task database.

It can be either a CLASS type, with the class path specified or a GRPC type with its address. The task chain uses this information to setup a ChainLink (A task in the chain)

model_template_id (str): ID of the model template model_template_path (str): path to the original model template file name (str): user-friendly name for the algorithm used in the task task_family (TaskFamily): overall task family of the task. One of VISION, FLOW_CONTROL AND DATASET. task_type (TaskType): Type of algorithm within task family. instantiation (InstantiationType): InstantiationType (CLASS or GRPC) summary (str): Summary of what the algorithm does. Defaults to “”. framework (Optional[str]): The framework used by the algorithm. Defaults to None. max_nodes (int): Max number of nodes for training. Defaults to 1. application (Optional[str]): Name of the application solved by this algorithm. Defaults to None. dependencies (Liar[Dependency]): List of dependencies required by the algorithm. Defaults to empty field. initial_weights (Optional[str]): Optional URL to the initial weights used by the algorithm. Defaults to None training_targets (List[TargetDevice]): device used for training. Defaults to empty field. inference_targets (List[TargetDevices]): device used for inference. Defaults to empty field. dataset_requirements (DatasetRequirements): list of dataset requirements. Defaults to empty field. model_optimization_methods (List[ModelOptimizationMethod]): list of ModelOptimizationMethod.

This lists all methods available to optimize the inference model for the task

hyper_parameters (HyperParameterData): HyperParameterData object containing the base path to the configurable

parameter definition, as well as any overrides for the base parameters that are specific for the current template.

is_trainable (bool): specify whether task is trainable capabilities (List[str]): list of task capabilities grpc_address (Optional[str]): the grpc host address (for instantiation type == GRPC) entrypoints (Optional[Entrypoints]): Entrypoints implementing the Python task interface base_model_path (str): Path to template file for the base model used for nncf compression. exportable_code_paths (ExportableCodePaths): if it exists, the path to the exportable code sources.

Defaults to empty field.

task_type_sort_priority (int): priority of order of how tasks are shown in the pipeline dropdown for a given task

type. E.g. for classification Inception is default and has weight 0. Unassigned priority will have -1 as priority. mobilenet is less important, and has a higher value. Default is zero (the highest priority).

gigaflops (float): how many billions of operations are required to do inference on a single data item. size (float): how much disk space the model will approximately take.

application: Optional[str] = None#
base_model_path: str = ''#
capabilities: List[str]#
computes_representations() bool#

Returns true if “compute_representations” is in capabilities.

computes_uncertainty_score() bool#

Returns true if “compute_uncertainty_score” is in capabilities false otherwise.

dataset_requirements: DatasetRequirements#
dependencies: List[Dependency]#
entrypoints: Optional[EntryPoints] = None#
exportable_code_paths: ExportableCodePaths#
framework: Optional[str] = None#
gigaflops: float = 0#
grpc_address: Optional[str] = None#
hpo: Optional[Dict] = None#
hyper_parameters: HyperParameterData#
inference_targets: List[TargetDevice]#
initial_weights: Optional[str] = None#
instantiation: InstantiationType#
is_task_global() bool#

Returns True if the task is global task i.e. if task produces global labels.

is_trainable: bool = True#
max_nodes: int = 1#
model_optimization_methods: List[ModelOptimizationMethod]#
model_template_id: str#
model_template_path: str#
name: str#
size: float = 0#
summary: str = ''#
supports_auto_hpo() bool#

Returns True if the algorithm supports automatic hyper parameter optimization, False otherwise.

task_family: TaskFamily#
task_type: TaskType#
task_type_sort_priority: int = -1#
training_targets: List[TargetDevice]#
class otx.api.entities.model_template.NullModelTemplate#

Represent an empty model template. Note that a task based on this model template cannot be instantiated.

capabilities: List[str]#
dataset_requirements: DatasetRequirements#
dependencies: List[Dependency]#
exportable_code_paths: ExportableCodePaths#
hyper_parameters: HyperParameterData#
inference_targets: List[TargetDevice]#
instantiation: InstantiationType#
model_optimization_methods: List[ModelOptimizationMethod]#
model_template_id: str#
model_template_path: str#
name: str#
task_family: TaskFamily#
task_type: TaskType#
training_targets: List[TargetDevice]#
class otx.api.entities.model_template.TargetDevice(value)#

Represents the target device for a given model.

This device might be used for instance be used for training or inference.

CPU = 2#
GPU = 3#
UNSPECIFIED = 1#
VPU = 4#
class otx.api.entities.model_template.TaskFamily(value)#

Overall task family.

DATASET = 3#
FLOW_CONTROL = 2#
VISION = 1#
class otx.api.entities.model_template.TaskInfo(domain: Domain, is_trainable: bool, is_anomaly: bool, is_global: bool, is_local: bool)#

Task information.

NamedTuple to store information about the task type like label domain, if it is trainable, if it is an anomaly task and if it supports global or local labels.

domain: Domain#

Alias for field number 0

is_anomaly: bool#

Alias for field number 2

is_global: bool#

Alias for field number 3

is_local: bool#

Alias for field number 4

is_trainable: bool#

Alias for field number 1

class otx.api.entities.model_template.TaskType(value)#

The type of algorithm within the task family.

Also contains relevant information about the task type like label domain, if it is trainable, if it is an anomaly task or if it supports global or local labels.

Args:

value (int): (Unused) Unique integer for .value property of Enum (auto() does not work) task_info (TaskInfo): NamedTuple containing information about the task’s capabilities

ACTION_CLASSIFICATION = 14#
ACTION_DETECTION = 15#
ACTIVELEARNING = 10#
ANOMALY_CLASSIFICATION = 12#
ANOMALY_DETECTION = 6#
ANOMALY_SEGMENTATION = 11#
CLASSIFICATION = 3#
CROP = 7#
DATASET = 2#
DETECTION = 5#
INSTANCE_SEGMENTATION = 9#
NULL = 1#
ROTATED_DETECTION = 13#
SEGMENTATION = 4#
TILE = 8#
otx.api.entities.model_template.parse_model_template(model_template_path: str) ModelTemplate#

Read a model template from a file.

Args:

model_template_path (str): Path to the model template template.yaml file

Returns:

ModelTemplate: The model template parsed from the file.

otx.api.entities.model_template.parse_model_template_from_dict(model_template_dict: dict) ModelTemplate#

Read a model template from a dictionary.

Note that the model_template_id must be defined inside the dictionary.

Args:

model_template_dict (dict): Dictionary containing the model template.

Returns:

ModelTemplate: The model template.

otx.api.entities.model_template.task_type_to_label_domain(task_type: TaskType) Domain#

Links the task type to the label domain enum.

Note that not all task types have an associated domain (e.g. crop task). In this case, a ValueError is raised.

Args:

task_type (TaskType): The task type to get the label domain for.

Returns:

Domain: The label domain for the task type.

This file defines the ModelConfiguration, ModelEntity and Model classes.

class otx.api.entities.model.ModelConfiguration(configurable_parameters: ConfigurableParameters, label_schema: LabelSchemaEntity)#

This class represents the task configuration which was used to generate a specific model.

Those are the parameters that a task may need in order to use the model.

Args:
configurable_parameters: Task configurable parameters used to

generate the model

label_schema: Label schema inside the project used to generate

the model

configurable_parameters: ConfigurableParameters#
get_label_schema() LabelSchemaEntity#

Get the LabelSchema.

class otx.api.entities.model.ModelEntity(train_dataset: DatasetEntity, configuration: ModelConfiguration, *, creation_date: Optional[datetime] = None, performance: Optional[Performance] = None, previous_trained_revision: Optional[ModelEntity] = None, previous_revision: Optional[ModelEntity] = None, version: int = 1, tags: Optional[List[str]] = None, model_format: ModelFormat = ModelFormat.OPENVINO, training_duration: float = 0.0, model_adapters: Optional[Dict[str, ModelAdapter]] = None, exportable_code_adapter: Optional[ExportableCodeAdapter] = None, precision: Optional[List[ModelPrecision]] = None, latency: int = 0, fps_throughput: int = 0, target_device: TargetDevice = TargetDevice.CPU, target_device_type: Optional[str] = None, optimization_type: ModelOptimizationType = ModelOptimizationType.NONE, optimization_methods: List[OptimizationMethod] = None, optimization_objectives: Dict[str, str] = None, performance_improvement: Dict[str, float] = None, model_size_reduction: float = 0.0, _id: Optional[ID] = None)#

Represents the Entity of a Model.

property configuration: ModelConfiguration#

Gets or sets the configuration of the Model.

property creation_date: datetime#

Gets or sets the creation_date of the Model.

delete_data(key: str)#

This function is used to delete data sources that are on the filesystem.

If the key exists the model adapter will be appended to a list of model adapter that will be removed once the model is saved by the repo. Note that an optimized model must contain at least 1 DataSource otherwise you are left with an invalid optimized model.

property exportable_code: Optional[bytes]#

Get the exportable_code from the exportable code adapter.

property exportable_code_adapter: Optional[ExportableCodeAdapter]#

Returns the exportable code adapter.

property fps_throughput: int#

Get or set the throughput of the model.

Unit is frames per second (fps)

get_data(key: str) bytes#

Fetches byte data for a certain model.

Args:

key: key to fetch data for

Returns:

bytes: data for the key.

property id: ID#

DEPRECATED.

property id_: ID#

Gets or sets the id of a Model.

is_optimized() bool#

Returns a boolean indicating if the model has been optimized or not.

property latency: int#

Get or set the latency of the model.

Unit is milliseconds (ms)

property model_adapters: Dict[str, ModelAdapter]#

Returns the dictionary of model adapters for each data key.

property model_format: ModelFormat#

Gets the model format.

property model_size_reduction: float#

Get or set the reduction in model size by optimizing.

property optimization_methods: Optional[List[OptimizationMethod]]#

Get or set the optimization methods used on the model.

property optimization_objectives: Optional[Dict[str, str]]#

Get or set the optimization level of the model.

property optimization_type: ModelOptimizationType#

Get or set the optimization type used for the model.

property performance: Performance#

Gets or sets the current Performance of the Model.

property performance_improvement: Optional[Dict[str, float]]#

Get or set the performance improvement of the model.

property precision: List[ModelPrecision]#

Get or set the precision for the model.

This has effect on accuracy, latency and throughput of the model.

property previous_revision: Union[None, ModelEntity]#

Gets or sets the previous model.

property previous_trained_revision: Union[None, ModelEntity]#

Gets or sets the previous model.

Returns:

None if no previous_trained_revision has been created

set_data(key: str, data: Union[bytes, IDataSource], skip_deletion=False)#

Sets the data for a specified key, either from a binary blob or from a data source.

If the key already exists it appends existing data url to a list of urls that will be removed upon saving the model. Skip deletion parameter should only be true if replacing bytes data with a file.

property tags: List[str]#

Gets or sets the tags of the Model.

property target_device: TargetDevice#

Get or set the device on which the model will be deployed.

property target_device_type: Optional[str]#

Get or set the type of the target device used by the model.

property train_dataset: DatasetEntity#

Gets or sets the current Training Dataset.

property training_duration: float#

Gets or sets the current training duration.

property version: int#

Gets or sets the version.

property weight_paths: Dict[str, URL]#

Returns the the path to URLs for each data key.

Note that this function will raise an error if the model was not saved to a database.

class otx.api.entities.model.ModelFormat(value)#

Indicate the format of the model.

BASE_FRAMEWORK = 2#
ONNX = 3#
OPENVINO = 1#
class otx.api.entities.model.ModelOptimizationType(value)#

Represents optimization type that is used to optimize the model.

MO = 2#
NNCF = 3#
NONE = 1#
POT = 4#
class otx.api.entities.model.ModelPrecision(value)#

Represents the ModelPrecision of a Model.

FP16 = 3#
FP32 = 4#
INT4 = 1#
INT8 = 2#
class otx.api.entities.model.OptimizationMethod(value)#

Represents optimization method that is used to optimize the model.

FILTER_PRUNING = 1#
QUANTIZATION = 2#

This module implements the OptimizationParameters entity.

class otx.api.entities.optimization_parameters.OptimizationParameters(resume: bool = False, update_progress: ~typing.Callable[[int, ~typing.Optional[float]], ~typing.Any] = <function default_progress_callback>, save_model: ~typing.Callable[[], None] = <function default_save_model_callback>)#

Optimization parameters.

resume (bool): Set to True if optimization must be resume with the optimizer state;

set to False to discard the optimizer state and start with fresh optimizer

update_progress (Callable[int], None): Callback which can be used to provide updates about the progress of a task. save_model (Callable[List, None]): Callback to notify that the model weights have been changed.

This callback can be used by the task when temporary weights should be saved (for instance, at the end of an epoch). If this callback has been used to save temporary weights, those weights will be used to resume optimization if for some reason training was suspended.

resume: bool = False#
save_model()#

This is the default save model callback for OptimizationParameters.

update_progress(score: Optional[float] = None)#

This is the default progress callback for OptimizationParameters.

otx.api.entities.optimization_parameters.default_progress_callback(progress: int, score: Optional[float] = None)#

This is the default progress callback for OptimizationParameters.

otx.api.entities.optimization_parameters.default_save_model_callback()#

This is the default save model callback for OptimizationParameters.

This module implements the ResultMediaEntity.

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

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
    )
Args:

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.

This module implements the ResultSet entity.

class otx.api.entities.resultset.ResultSetEntity(model: ModelEntity, ground_truth_dataset: DatasetEntity, prediction_dataset: DatasetEntity, purpose: ResultsetPurpose = ResultsetPurpose.EVALUATION, performance: Optional[Performance] = None, creation_date: Optional[datetime] = None, id: Optional[ID] = None)#

ResultsetEntity.

It aggregates:
  • the dataset containing ground truth (based on user annotations)

  • the dataset containing predictions for the above ground truth dataset

In addition, it links to the model which computed the predictions, as well as the performance of this model on the ground truth dataset.

Args:
model: the model using which the prediction_dataset has been

generated

ground_truth_dataset: the dataset containing ground truth

annotation

prediction_dataset: the dataset containing prediction purpose: see ResultsetPurpose performance: the performance of the model on the ground truth

dataset

creation_date: the date time which the resultset is created. Set

to None to set this to

id: the id of the resultset. Set to ID() so that a new unique ID

will be assigned upon saving. If the argument is None, it will be set to ID()

datetime.now(datetime.timezone.utc)

property creation_date: datetime#

Returns the creation date of the ResultSet.

property ground_truth_dataset: DatasetEntity#

Returns the ground truth dataset that is used in the ResultSet.

has_score_metric() bool#

Returns True if the resultset contains non-null performance and score value.

property id: ID#

DEPRECATED.

property id_: ID#

Returns the id of the ResultSet.

property model: ModelEntity#

Returns the model that is used for the ResultSet.

property performance: Performance#

Returns the performance of the model on the ground truth dataset.

property prediction_dataset: DatasetEntity#

Returns the prediction dataset that is used in the ResultSet.

property purpose: ResultsetPurpose#

Returns the purpose of the ResultSet, for example ResultSetPurpose.EVALUATION.

class otx.api.entities.resultset.ResultsetPurpose(value)#

This defines the purpose of the resultset.

EVALUATION denotes resultsets generated at Evaluation stage on validation subset.

TEST denotes resultsets generated at Evaluation stage on test subset.

PREEVALUATION denotes resultsets generated at Preevaluation stage (e.g., train from scratch) onn validation subset.

EVALUATION = 0#
PREEVALUATION = 2#
TEST = 1#

This module define the scored label entity.

class otx.api.entities.scored_label.LabelSource(user_id: str = '', model_id: ID = ID(), model_storage_id: ID = ID())#

This dataclass contains information about the source of a scored label.

For annotations, the id of the user who created the label and for predictions, the id and model storage id of the model that created the prediction. When a user has accepted a predictions as is, both the user id of the user who accepted and the model/model storage id of the model that predicted should be filled in.

model_id: ID = ID()#
model_storage_id: ID = ID()#
user_id: str = ''#
class otx.api.entities.scored_label.ScoredLabel(label: LabelEntity, probability: float = 0.0, label_source: Optional[LabelSource] = None)#

This represents a label along with a probability. This is used inside Annotation class.

Args:

label (LabelEntity): Label entity to which probability and source are attached. probability (float): a float denoting the probability of the shape belonging to the label. label_source (LabelSource): a LabelSource dataclass containing the id of the user who created

or the model that predicted this label.

property color: Color#

Color of the label.

property creation_date: datetime#

Creation data of the label.

property domain: Domain#

Domain of the label.

get_label() LabelEntity#

Gets the label that the ScoredLabel object was initialized with.

property hotkey: str#

Hotkey of the label.

property id: ID#

DEPRECATED.

property id_: ID#

Returns the label id.

property is_empty: bool#

Check if the label is empty.

property name: str#

Name of the label.

This file defines the Subset enum for use in datasets.

class otx.api.entities.subset.Subset(value)#

Describes the Subset a DatasetItem is assigned to.

NONE = 0#
PSEUDOLABELED = 5#
TESTING = 3#
TRAINING = 1#
UNASSIGNED = 6#
UNLABELED = 4#
VALIDATION = 2#

This module implements the TaskEnvironment entity.

class otx.api.entities.task_environment.TaskEnvironment(model_template: ModelTemplate, model: Optional[ModelEntity], hyper_parameters: ConfigurableParameters, label_schema: LabelSchemaEntity)#

Defines the machine learning environment the task runs in.

Args: model_template (ModelTemplate): The model template used for this task model (Optional[ModelEntity]): Model to use; if not specified, the task must be either weight-less

or use pre-trained or randomly initialised weights.

hyper_parameters (ConfigurableParameters): Set of hyper parameters label_schema (LabelSchemaEntity): Label schema associated to this task

get_hyper_parameters(instance_of: Optional[Type[TypeVariable]] = None) TypeVariable#

Returns Configuration for the task, de-serialized as type specified in instance_of.

If the type of the configurable parameters is unknown, a generic ConfigurableParameters object with all available parameters can be obtained by calling method with instance_of = None.

Example:
>>> self.get_hyper_parameters(instance_of=TorchSegmentationConfig)
TorchSegmentationConfig()
Args:

instance_of (Optional[Type[TypeVariable]]): subtype of ModelConfig of the hyperparamters. Defaults to None.

Returns:

TypeVariable: ConfigurableParameters entity

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

Return the labels in this task environment (based on the label schema).

Args:

include_empty (bool): Include the empty label if True. Defaults to False.

Returns:

List[LabelEntity]: List of labels

get_model_configuration() ModelConfiguration#

Get the configuration needed to use the current model.

That is the current set of:
  • configurable parameters

  • labels

  • label schema

Returns:

ModelConfiguration: Model configuration

set_hyper_parameters(hyper_parameters: ConfigurableParameters)#

Sets the hyper parameters for the task.

Example:
>>> self.set_hyper_parameters(hyper_parameters=TorchSegmentationParameters())
None
Args:

hyper_parameters (ConfigurationParameter): ConfigurableParameters entity to assign to task

This module implements the Tensor entity.

class otx.api.entities.tensor.TensorEntity(name: str, numpy: ndarray)#

Represents a metadata of tensor type in OTX.

Args:

name: name of metadata numpy: the numpy data of the tensor

property numpy: ndarray#

Returns the numpy representation of the tensor.

property shape: Tuple[int, ...]#

Returns the shape of the tensor.

This module implements the TrainingParameters entity.

class otx.api.entities.train_parameters.TrainParameters(resume: bool = False, update_progress: ~typing.Callable[[int, ~typing.Optional[float]], ~typing.Any] = <function default_progress_callback>, save_model: ~typing.Callable[[], None] = <function default_save_model_callback>)#

Train parameters.

Attributes:
resume: Set to True if training must be resume with the

optimizer state; set to False to discard the optimizer state and start with fresh optimizer

update_progress: Callback which can be used to provide updates

about the progress of a task.

save_model: Callback to notify that the model weights have been

changed. This callback can be used by the task when temporary weights should be saved (for instance, at the end of an epoch). If this callback has been used to save temporary weights, those weights will be used to resume training if for some reason training was suspended.

resume: bool = False#
save_model()#

Default save model callback. It is a placeholder (does nothing) and is used in empty TrainParameters.

update_progress(score: Optional[float] = None)#

Default progress callback. It is a placeholder (does nothing) and is used in empty TrainParameters.

class otx.api.entities.train_parameters.UpdateProgressCallback(*args, **kwargs)#

UpdateProgressCallback protocol.

Used as a replacement of Callable[] type since Callable doesn’t handle default parameters like score: Optional[float] = None

otx.api.entities.train_parameters.default_progress_callback(progress: float, score: Optional[float] = None)#

Default progress callback. It is a placeholder (does nothing) and is used in empty TrainParameters.

otx.api.entities.train_parameters.default_save_model_callback()#

Default save model callback. It is a placeholder (does nothing) and is used in empty TrainParameters.

This file defines the URL class.

class otx.api.entities.url.URL(url: Union[URL, str])#

Class for working with URLs.

Provides functions for getting components of the URL such as <scheme>://<host>/<path>

property extension#

Gets the extension of the URL.

property host#

Gets the host of the URL.

property path#

Returns the full path to the full.

property relative_path#

Returns the relative path to the full.

property scheme#

Gets the scheme of the URL.