otx.core.exporter.visual_prompting#
Class definition for visual prompting model exporter used in OTX.
Classes
|
Exporter for visual prompting models that uses native torch and OpenVINO conversion tools. |
- class otx.core.exporter.visual_prompting.OTXVisualPromptingModelExporter(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, via_onnx: bool = False, onnx_export_configuration: dict[str, Any] | None = None, output_names: list[str] | None = None, input_names: list[str] | None = None)[source]#
Bases:
OTXNativeModelExporter
Exporter for visual prompting models that uses native torch and OpenVINO conversion tools.
- 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) dict[str, 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. Currently not supported by Visual Promting task.
- Returns:
paths to the exported models
- Return type:
- get_onnx_dummy_inputs(base_model_name: Literal['exported_model_image_encoder', 'exported_model_decoder'], model: Module) dict[str, Any] [source]#
Get onnx dummy inputs.
- to_onnx(model: OTXModel | torch.nn.Module, output_dir: Path, base_model_name: str = 'exported_model', precision: OTXPrecisionType = OTXPrecisionType.FP32, embed_metadata: bool = True, model_type: str = 'sam') Path [source]#
Export the given PyTorch model to ONNX format and save it to the specified output directory.
- Parameters:
model (OTXModel) – OTXModel to be exported.
output_dir (Path) – The directory where the ONNX model will be saved.
base_model_name (str, optional) – The base name for the exported model. Defaults to “exported_model”.
precision (OTXPrecisionType, optional) – The precision type for the exported model.
OTXPrecisionType.FP32. (Defaults to) –
embed_metadata (bool, optional) – Whether to embed metadata in the ONNX model. Defaults to True.
- Returns:
The path to the saved ONNX model.
- Return type:
Path
- to_openvino(model: OTXModel | torch.nn.Module, output_dir: Path, base_model_name: str = 'exported_model', precision: OTXPrecisionType = OTXPrecisionType.FP32, model_type: str = 'sam') Path [source]#
Export to OpenVINO Intermediate Representation format.
In this implementation the export is done only via standard OV/ONNX tools.