Tasks#

Initialization of OTX Anomalib.

class otx.algorithms.anomaly.tasks.InferenceTask(task_environment: TaskEnvironment, output_path: Optional[str] = None)#

Base Anomaly Task.

cancel_training() None#

Cancel the training after_batch_end.

This terminates the training; however validation is still performed.

cleanup() None#

Clean up work directory.

evaluate(output_resultset: ResultSetEntity, evaluation_metric: Optional[str] = None) None#

Evaluate the performance on a result set.

Args:

output_resultset (ResultSetEntity): Result Set from which the performance is evaluated. evaluation_metric (Optional[str], optional): Evaluation metric. Defaults to None. Instead,

metric is chosen depending on the task type.

export(export_type: ExportType, output_model: ModelEntity, precision: ModelPrecision = ModelPrecision.FP32, dump_features: bool = False) None#

Export model to OpenVINO IR.

Args:

export_type (ExportType): Export type should be ExportType.OPENVINO output_model (ModelEntity): The model entity in which to write the OpenVINO IR data precision (bool): Output model weights and inference precision dump_features (bool): Flag to return “feature_vector” and “saliency_map”.

Raises:

Exception: If export_type is not ExportType.OPENVINO

get_config() Union[DictConfig, ListConfig]#

Get Anomalib Config from task environment.

Returns:

Union[DictConfig, ListConfig]: Anomalib config.

infer(dataset: DatasetEntity, inference_parameters: InferenceParameters) DatasetEntity#

Perform inference on a dataset.

Args:

dataset (DatasetEntity): Dataset to infer. inference_parameters (InferenceParameters): Inference parameters.

Returns:

DatasetEntity: Output dataset with predictions.

load_model(otx_model: Optional[ModelEntity]) AnomalyModule#

Create and Load Anomalib Module from OTX Model.

This method checks if the task environment has a saved OTX Model, and creates one. If the OTX model already exists, it returns the the model with the saved weights.

Args:
otx_model (Optional[ModelEntity]): OTX Model from the

task environment.

Returns:
AnomalyModule: Anomalib

classification or segmentation model with/without weights.

model_info() Dict#

Return model info to save the model weights.

Returns:

Dict: Model info.

save_model(output_model: ModelEntity) None#

Save the model after training is completed.

Args:

output_model (ModelEntity): Output model onto which the weights are saved.

unload() None#

Unload the task.

class otx.algorithms.anomaly.tasks.NNCFTask(task_environment: TaskEnvironment, **kwargs)#

Base Anomaly Task.

load_model(otx_model: Optional[ModelEntity]) AnomalyModule#

Create and Load Anomalib Module from OTX Model.

This method checks if the task environment has a saved OTX Model, and creates one. If the OTX model already exists, it returns the the model with the saved weights.

Args:
otx_model (Optional[ModelEntity]): OTX Model from the

task environment.

Returns:
AnomalyModule: Anomalib

classification or segmentation model with/without weights.

model_info() Dict#

Return model info to save the model weights.

Returns:

Dict: Model info.

optimize(optimization_type: OptimizationType, dataset: DatasetEntity, output_model: ModelEntity, optimization_parameters: Optional[OptimizationParameters] = None)#

Train the anomaly classification model.

Args:

optimization_type (OptimizationType): Type of optimization. dataset (DatasetEntity): Input dataset. output_model (ModelEntity): Output model to save the model weights. optimization_parameters (OptimizationParameters): Training parameters

class otx.algorithms.anomaly.tasks.OpenVINOTask(task_environment: TaskEnvironment)#

OpenVINO inference task.

Args:

task_environment (TaskEnvironment): task environment of the trained anomaly model

deploy(output_model: ModelEntity) None#

Exports the weights from output_model along with exportable code.

Args:

output_model (ModelEntity): Model with openvino.xml and .bin keys

Raises:

Exception: If task_environment.model is None

evaluate(output_resultset: ResultSetEntity, evaluation_metric: Optional[str] = None)#

Evaluate the performance of the model.

Args:

output_resultset (ResultSetEntity): Result set storing ground truth and predicted dataset. evaluation_metric (Optional[str], optional): Evaluation metric. Defaults to None.

get_config() Dict#

Get Anomalib Config from task environment.

Returns:

ADDict: Anomalib config

get_meta_data() Dict#

Get Meta Data.

infer(dataset: DatasetEntity, inference_parameters: InferenceParameters) DatasetEntity#

Perform Inference.

Args:

dataset (DatasetEntity): Inference dataset inference_parameters (InferenceParameters): Inference parameters.

Returns:

DatasetEntity: Output dataset storing inference predictions.

load_inferencer() OpenVINOInferencer#

Create the OpenVINO inferencer object.

Returns:

OpenVINOInferencer object

optimize(optimization_type: OptimizationType, dataset: DatasetEntity, output_model: ModelEntity, optimization_parameters: Optional[OptimizationParameters])#

Optimize the model.

Args:

optimization_type (OptimizationType): Type of optimization [POT or NNCF] dataset (DatasetEntity): Input Dataset. output_model (ModelEntity): Output model. optimization_parameters (Optional[OptimizationParameters]): Optimization parameters.

Raises:

ValueError: When the optimization type is not POT, which is the only support type at the moment.

class otx.algorithms.anomaly.tasks.TrainingTask(task_environment: TaskEnvironment, output_path: Optional[str] = None)#

Base Anomaly Task.

load_model(otx_model: Optional[ModelEntity]) AnomalyModule#

Create and Load Anomalib Module from OTE Model.

This method checks if the task environment has a saved OTE Model, and creates one. If the OTE model already exists, it returns the the model with the saved weights.

Args:
otx_model (Optional[ModelEntity]): OTE Model from the

task environment.

Returns:
AnomalyModule: Anomalib

classification or segmentation model with/without weights.

train(dataset: DatasetEntity, output_model: ModelEntity, train_parameters: TrainParameters, seed: Optional[int] = None) None#

Train the anomaly classification model.

Args:

dataset (DatasetEntity): Input dataset. output_model (ModelEntity): Output model to save the model weights. train_parameters (TrainParameters): Training parameters seed: (Optional[int]): Setting seed to a value other than 0 also marks PytorchLightning trainer’s

deterministic flag to True.