otx.backend.openvino.engine#

OpenVINO engine.

Classes

OVEngine(data, model[, work_dir])

OV Engine.

class otx.backend.openvino.engine.OVEngine(data: OTXDataModule | str | Path | PathLike, model: OVModel | str | Path | PathLike, work_dir: str | Path | PathLike = './otx-workspace')[source]#

Bases: Engine

OV Engine.

This class defines the OV Engine for OTX, which governs each step of the OpenVINO validation workflow.

Initialize the OVEngine.

Parameters:
  • data (OTXDataModule | PathLike) – The data module or path to the data root. If a path is provided, the engine will automatically create a datamodule based on the data root and model.

  • model (OVModel | PathLike) – The OV model for the engine. A PathLike object to an OpenVINO IR XML file can also be provided. Defaults to None.

  • work_dir (PathLike, optional) – Working directory for the engine. Defaults to “./otx-workspace”.

export(*args, **kwargs) Path[source]#

Export method is not supported for OVEngine.

static is_supported(model: MODEL, data: DATA) bool[source]#

Check if the engine is supported for the given model and data.

log_results(metrics: METRICS) None[source]#

Log testing phase results to a CSV file.

This function behaves similarly to OTXModel._log_metrics(metrics, key=”test”).

optimize(checkpoint: str | Path | PathLike | None = None, datamodule: OTXDataModule | None = None, max_data_subset_size: int | None = None) Path[source]#

Apply Post-Training Quantization (PTQ) to optimize the model.

PTQ performs int-8 quantization on the input model, resulting in mixed precision.

Parameters:
  • checkpoint (PathLike | None, optional) – Checkpoint to optimize. Defaults to None.

  • datamodule (OTXDataModule | None, optional) – The data module to use for optimization.

  • max_data_subset_size (int | None, optional) – Maximum size of the train subset used for optimization. Defaults to None.

Returns:

Path to the optimized model.

Return type:

Path

predict(data: OTXDataModule | PathLike | list[np.array] | None = None, checkpoint: PathLike | None = None, explain: bool = False, explain_config: ExplainConfig | None = None, **kwargs) ANNOTATIONS[source]#

Run predictions using the specified model and data.

Parameters:
  • data (OTXDataModule | PathLike | list[np.array] | None, optional) – The data module, path to data root, or a list of numpy images to use for predictions.

  • checkpoint (PathLike | None, optional) – The path to the IR XML file to load the model from.

  • explain (bool, optional) – Whether to generate “saliency_map” and “feature_vector”. Defaults to False.

  • explain_config (ExplainConfig | None, optional) – Configuration for saliency map post-processing.

Returns:

The predictions made by the model on the provided data.

(list of OTXPredEntity)

Return type:

ANNOTATIONS

Raises:
  • ValueError – If input data is invalid or label information does not match.

  • TypeError – If input data type is unsupported.

test(data: OTXDataModule | PathLike | None = None, checkpoint: PathLike | None = None, metric: MetricCallable | None = None, **kwargs) METRICS[source]#

Run the testing phase of the engine.

Parameters:
  • data (OTXDataModule | PathLike | None, optional) – The data to test on. It can be a data module or a path to the data root. If a path is provided, the engine will automatically create a datamodule based on the data root and model.

  • checkpoint (PathLike | None, optional) – Path to the checkpoint file to load the model from. Defaults to None.

  • metric (MetricCallable | None, optional) – If provided, overrides OTXModel.metric_callable with the given metric callable for evaluation.

Returns:

The computed metrics after testing the model on the provided data.

(dictionary of metric names and values)

Return type:

METRICS

Raises:
  • RuntimeError – If required data or metric is not provided.

  • ValueError – If label information between model and datamodule does not match.

train(*args, **kwargs) METRICS[source]#

Train method is not supported for OVEngine.

property datamodule: OTXDataModule#

Get the datamodule associated with the engine.

Returns:

The OTXDataModule object.

Return type:

OTXDataModule

Raises:

RuntimeError – If the datamodule is not set.

property model: OVModel#

Get the model associated with the engine.

Returns:

The OVModel object or None if not set.

Return type:

OVModel

property work_dir: str | Path | PathLike#

Get the working directory.

Returns:

The working directory path.

Return type:

PathLike