otx.api.entities.model_template#
This file defines the ModelConfiguration, ModelEntity and Model classes.
Functions
|
Read a model template from a file. |
Read a model template from a dictionary. |
|
|
Links the task type to the label domain enum. |
Classes
|
Expected requirements for the dataset in order to use this algorithm. |
|
Dependency required by the task. |
|
Path of the Python classes implementing the task interface. |
|
The paths to the different versions of the exportable code for a given model template. |
|
HyperParameter Data. |
|
The method to instantiate a given task. |
|
Represents model category regarding accuracy & speed trade-off. |
|
Optimized model format. |
|
Represents model status regarding deprecation process. |
|
This class represents a Task in the Task database. |
Represent an empty model template. |
|
|
Represents the target device for a given model. |
|
Overall task family. |
|
Task information. |
|
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.
- 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.
- 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:
- 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.
- 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.
- 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.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)
- 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.
- 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:
- 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: