otx.api.entities.model_template#

This file defines the ModelConfiguration, ModelEntity and Model classes.

Functions

parse_model_template(model_template_path)

Read a model template from a file.

parse_model_template_from_dict(...)

Read a model template from a dictionary.

task_type_to_label_domain(task_type)

Links the task type to the label domain enum.

Classes

DatasetRequirements([classes])

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

Dependency(source, destination[, size, sha256])

Dependency required by the task.

EntryPoints(base[, openvino, nncf])

Path of the Python classes implementing the task interface.

ExportableCodePaths([default, openvino])

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

HyperParameterData(base_path, ...)

HyperParameter Data.

InstantiationType(value)

The method to instantiate a given task.

ModelCategory(value)

Represents model category regarding accuracy & speed trade-off.

ModelOptimizationMethod(value)

Optimized model format.

ModelStatus(value)

Represents model status regarding deprecation process.

ModelTemplate(model_template_id, ...)

This class represents a Task in the Task database.

NullModelTemplate()

Represent an empty model template.

TargetDevice(value)

Represents the target device for a given model.

TaskFamily(value)

Overall task family.

TaskInfo(domain, is_trainable, is_anomaly, ...)

Task information.

TaskType(value)

The type of algorithm within the task family.

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

Bases: object

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

classes#

Classes which must be present in the dataset

Type:

Optional[List[str]]

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

Bases: object

Dependency required by the task.

source#

Source of the dependency

Type:

str

destination#

Destination folder to install the dependency

Type:

str

size#

Size of the dependency in bytes

Type:

Optional[int]

sha256#

SHA-256 checksum of the dependency file

Type:

Optional[str]

class otx.api.entities.model_template.EntryPoints(base: str, openvino: str | None = None, nncf: str | None = None)[source]#

Bases: object

Path of the Python classes implementing the task interface.

base#

Base interface implementing the functionality in a framework such as PyTorch or TensorFlow

Type:

str

openvino#

OpenVINO interface.

Type:

Optional[str]

nncf#

NNCF interface

Type:

Optional[str]

class otx.api.entities.model_template.ExportableCodePaths(default: str | None = None, openvino: str | None = None)[source]#

Bases: object

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

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

Bases: object

HyperParameter Data.

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

base_path#

The path to the yaml file specifying the base configurable parameters to use in the model. Defaults to None.

Type:

Optional[str]

parameter_overrides#

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.

Type:

Dict

load_parameters(model_template_path: str)[source]#

Load hyper parameters.

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

Parameters:

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

manually_set_data_and_validate(hyper_parameters: dict)[source]#

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.

Parameters:

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

substitute_parameter_overrides()[source]#

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.

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.

class otx.api.entities.model_template.InstantiationType(value)[source]#

Bases: Enum

The method to instantiate a given task.

class otx.api.entities.model_template.ModelCategory(value)[source]#

Bases: Enum

Represents model category regarding accuracy & speed trade-off.

class otx.api.entities.model_template.ModelOptimizationMethod(value)[source]#

Bases: Enum

Optimized model format.

class otx.api.entities.model_template.ModelStatus(value)[source]#

Bases: Enum

Represents model status regarding deprecation process.

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: str | None = None, max_nodes: int = 1, application: str | None = None, dependencies: ~typing.List[~otx.api.entities.model_template.Dependency] = <factory>, initial_weights: str | None = 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: str | None = None, entrypoints: ~otx.api.entities.model_template.EntryPoints | None = 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.Dict | None = None, model_category: ~otx.api.entities.model_template.ModelCategory = ModelCategory.OTHER, model_status: ~otx.api.entities.model_template.ModelStatus = ModelStatus.ACTIVE, is_default_for_task: bool = False)[source]#

Bases: object

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. model_category (ModelCategory): Represents model category regarding accuracy & speed trade-off. Default to OTHER. model_status (ModelStatus): Represents model status regarding deprecation process. Default to ACTIVE. is_default_for_task (bool): Whether this model is a default recommendation for the task

computes_representations() bool[source]#

Returns true if “compute_representations” is in capabilities.

computes_uncertainty_score() bool[source]#

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

is_task_global() bool[source]#

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

supports_auto_hpo() bool[source]#

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

class otx.api.entities.model_template.NullModelTemplate[source]#

Bases: ModelTemplate

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

class otx.api.entities.model_template.TargetDevice(value)[source]#

Bases: IntEnum

Represents the target device for a given model.

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

class otx.api.entities.model_template.TaskFamily(value)[source]#

Bases: Enum

Overall task family.

class otx.api.entities.model_template.TaskInfo(domain: Domain, is_trainable: bool, is_anomaly: bool, is_global: bool, is_local: bool)[source]#

Bases: NamedTuple

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.

Create new instance of TaskInfo(domain, is_trainable, is_anomaly, is_global, is_local)

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)[source]#

Bases: Enum

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.

Parameters:
  • 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

otx.api.entities.model_template.parse_model_template(model_template_path: str) ModelTemplate[source]#

Read a model template from a file.

Parameters:

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

Returns:

The model template parsed from the file.

Return type:

ModelTemplate

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

Read a model template from a dictionary.

Note that the model_template_id must be defined inside the dictionary.

Parameters:

model_template_dict (dict) – Dictionary containing the model template.

Returns:

The model template.

Return type:

ModelTemplate

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

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.

Parameters:

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

Returns:

The label domain for the task type.

Return type:

Domain