otx.core.exporter.base#

Class definition for base model exporter used in OTX.

Classes

OTXModelExporter(...[, mean, std, ...])

Base class for the model exporters used in OTX.

class otx.core.exporter.base.OTXModelExporter(task_level_export_parameters: TaskLevelExportParameters, input_size: tuple[int, ...], mean: tuple[float, float, float] = (0.0, 0.0, 0.0), std: tuple[float, float, float] = (1.0, 1.0, 1.0), resize_mode: Literal['crop', 'standard', 'fit_to_window', 'fit_to_window_letterbox'] = 'standard', pad_value: int = 0, swap_rgb: bool = False, output_names: list[str] | None = None)[source]#

Bases: object

Base class for the model exporters used in OTX.

Parameters:
  • task_level_export_parameters (TaskLevelExportParameters) – Collection of export parameters which can be defined at a task level.

  • input_size (tuple[int, ...]) – Input shape.

  • mean (tuple[float, float, float], optional) – Mean values of 3 channels. Defaults to (0.0, 0.0, 0.0).

  • std (tuple[float, float, float], optional) – Std values of 3 channels. Defaults to (1.0, 1.0, 1.0).

  • resize_mode (Literal["crop", "standard", "fit_to_window", "fit_to_window_letterbox"], optional) – A resize type for model preprocess. “standard” resizes images without keeping ratio. “fit_to_window” resizes images while keeping ratio. “fit_to_window_letterbox” resizes images and pads images to fit the size. Defaults to “standard”.

  • pad_value (int, optional) – Padding value. Defaults to 0.

  • swap_rgb (bool, optional) – Whether to convert the image from BGR to RGB Defaults to False.

  • output_names (list[str] | None, optional) – Names for model’s outputs, which would be

  • Note (embedded into resulting model.) –

  • same (that order of the output names should be the) –

:param : :param as in the target model.:

export(model: OTXModel, output_dir: Path, base_model_name: str = 'exported_model', export_format: OTXExportFormatType = OTXExportFormatType.OPENVINO, precision: OTXPrecisionType = OTXPrecisionType.FP32, to_exportable_code: bool = False) Path[source]#

Exports input model to the specified deployable format, such as OpenVINO IR or ONNX.

Parameters:
  • model (OTXModel) – OTXModel to be exported

  • output_dir (Path) – path to the directory to store export artifacts

  • base_model_name (str, optional) – exported model name

  • format (OTXExportFormatType) – final format of the exported model

  • precision (OTXExportPrecisionType, optional) – precision of the exported model’s weights

  • to_exportable_code (bool, optional) – whether to generate exportable code

Returns:

path to the exported model

Return type:

Path

to_exportable_code(model: OTXModel, output_dir: Path, base_model_name: str = 'exported_model', precision: OTXPrecisionType = OTXPrecisionType.FP32) Path[source]#

Export to zip folder final OV IR model with runable demo.

Parameters:
  • model (OTXModel) – OTXModel to be exported

  • output_dir (Path) – path to the directory to store export artifacts

  • base_model_name (str, optional) – exported model name

  • precision (OTXExportPrecisionType, optional) – precision of the exported model’s weights

Returns:

path to the exported model.

Return type:

Path

abstract to_onnx(model: OTXModel, output_dir: Path, base_model_name: str = 'exported_model', precision: OTXPrecisionType = OTXPrecisionType.FP32, embed_metadata: bool = True) Path[source]#

Abstract method for ONNX export.

Converts the given torch model to ONNX format and saves it to the specified output directory.

Parameters:
  • model (OTXModel) – The input PyTorch model to be converted.

  • output_dir (Path) – The directory where the ONNX model will be saved.

  • base_model_name (str, optional) – The name of the exported ONNX model. Defaults to “exported_model”.

  • precision (OTXPrecisionType, optional) – The precision type for the exported model.

  • OTXPrecisionType.FP32. (Defaults to) –

  • embed_metadata (bool, optional) – Flag to embed metadata in the exported ONNX model. Defaults to True.

Returns:

The file path where the ONNX model is saved.

Return type:

Path

abstract to_openvino(model: OTXModel, output_dir: Path, base_model_name: str = 'exported_model', precision: OTXPrecisionType = OTXPrecisionType.FP32) Path[source]#

Export to OpenVINO Intermediate Representation format.

Parameters:
  • model (OTXModel) – OTXModel to be exported

  • output_dir (Path) – path to the directory to store export artifacts

  • base_model_name (str, optional) – exported model name

  • precision (OTXExportPrecisionType, optional) – precision of the exported model’s weights

Returns:

path to the exported model.

Return type:

Path

property metadata: dict[tuple[str, str], str]#

Collection of metadata to be stored in OpenVINO Intermediate Representation or ONNX.

This metadata is mainly used to support ModelAPI.