Tools#

sample.py.

This is a sample python script showing how to train an end-to-end OTX Anomaly Classification Task.

class otx.algorithms.anomaly.tools.sample.OtxAnomalyTask(dataset_path: str, train_subset: Dict[str, str], val_subset: Dict[str, str], test_subset: Dict[str, str], model_template_path: str, seed: Optional[int] = None)#

OTX Anomaly Classification Task.

static clean_up() None#

Clean up the results directory used by anomalib.

create_task(task: str) Any#

Create base torch or openvino task.

Args:

task (str): task type. Either base or openvino.

Returns:

Any: Base Torch or OpenVINO Task Class.

Example:
>>> self.create_task(task="base")
<anomaly_classification.torch_task.AnomalyClassificationTask>
create_task_environment() TaskEnvironment#

Create task environment.

static evaluate(task: IEvaluationTask, result_set: ResultSetEntity) None#

Evaluate the performance of the model.

Args:

task (IEvaluationTask): Task to evaluate the performance. Either torch or openvino. result_set (ResultSetEntity): Results set containing the true and pred datasets.

export() ModelEntity#

Export the model via openvino.

export_nncf() ModelEntity#

Export NNCF model via openvino.

get_dataclass() Union[Type[AnomalyDetectionDataset], Type[AnomalySegmentationDataset], Type[AnomalyClassificationDataset]]#

Gets the dataloader based on the task type.

Raises:

ValueError: Validates task type.

Returns:

Dataloader

infer(task: IInferenceTask, output_model: ModelEntity) ResultSetEntity#

Get the predictions using the base Torch or OpenVINO tasks and models.

Args:

task (IInferenceTask): Task to infer. Either torch or openvino. output_model (ModelEntity): Output model on which the weights are saved.

Returns:

ResultSetEntity: Results set containing the true and pred datasets.

optimize() None#

Optimize the model via POT.

optimize_nncf() None#

Optimize the model via NNCF.

train() ModelEntity#

Train the base Torch model.

otx.algorithms.anomaly.tools.sample.main() None#

Run sample.py with given CLI arguments.

otx.algorithms.anomaly.tools.sample.parse_args() Namespace#

Parse CLI arguments.

Returns:

(Namespace): CLI arguments.