Conversion Parameters#
This document describes all available parameters for openvino.convert_model, ovc,
and openvino.save_model without focusing on a particular framework model format.
Use this information for your reference as a common description of the conversion API
capabilities in general. Part of the options can be not relevant to some specific
frameworks. Use Supported Model Formats page for more
dedicated framework-dependent tutorials.
You can obtain a model from Hugging Face. When you need to convert it, in most cases, you can use the following simple syntax:
import openvino as ov
ov_model = ov.convert_model('path_to_your_model')
# or, when model is a Python model object
ov_model = ov.convert_model(model)
# Optionally adjust model by embedding pre-post processing here...
ov.save_model(ov_model, 'model.xml')
ovc path_to_your_model
Providing just a path to the model or model object as openvino.convert_model argument
is frequently enough to make a successful conversion. However, depending on the model
topology and original deep learning framework, additional parameters may be required,
which are described below.
example_inputparameter available in Pythonopenvino.convert_modelonly is intended to trace the model to obtain its graph representation. This parameter is crucial for converting PyTorch and Flax models and may sometimes be required for TensorFlow models. For more details, refer to the PyTorch Model Conversion, TensorFlow Model Conversion, or JAX/Flax Model Conversion.inputparameter to set or override shapes for model inputs. It configures dynamic and static dimensions in model inputs depending on your inference requirements. For more information on this parameter, refer to the Setting Input Shapes guide.outputparameter to select one or multiple outputs from the original model. This is useful when the model has outputs that are not required for inference in a deployment scenario. By specifying only necessary outputs, you can create a more compact model that infers faster.compress_to_fp16parameter that is provided byovcCLI tool andopenvino.save_modelPython function, gives controls over the compression of model weights to FP16 format when saving OpenVINO model to IR. This option is enabled by default which means all produced IRs are saved using FP16 data type for weights which saves up to 2x storage space for the model file and in most cases doesn’t sacrifice model accuracy. In case it does affect accuracy, the compression can be disabled by setting this flag toFalse:
import openvino as ov
ov_model = ov.convert_model(original_model)
ov.save_model(ov_model, 'model.xml', compress_to_fp16=False)
ovc path_to_your_model --compress_to_fp16=False
For details on how plugins handle compressed FP16 models, see
Inference Devices and Modes.
Note
FP16 compression is sometimes used as the initial step for INT8 quantization.
Refer to the Post-training optimization guide for more
information about that.
extensionparameter which makes possible conversion of the models consisting of operations that are not supported by OpenVINO out-of-the-box. It requires implementing of an OpenVINO extension first, please refer to Frontend Extensions guide.share_weigthsparameter with default valueTrueallows reusing memory with original weights. For models loaded in Python and then passed toopenvino.convert_model, that means that OpenVINO model will share the same areas in program memory where the original weights are located. For models loaded from files byopenvino.convert_model, file memory mapping is used to avoid extra memory allocation. When enabled, the original model cannot be modified (Python object cannot be deallocated and original model file cannot be deleted) for the whole lifetime of OpenVINO model. Even model inference by original framework can lead to model modification. If it is not desired, setshare_weights=Falsewhen callingopenvino.convert_model.Note
ovcdoes not haveshare_weightsoption and always uses sharing to reduce conversion time and consume less amount of memory during the conversion.output_modelparameter inovcandopenvino.save_modelspecifies name for output.xmlfile with the resulting OpenVINO IR. The accompanying.binfile name will be generated automatically by replacing.xmlextension with.binextension. The value ofoutput_modelmust end with.xmlextension. Forovccommand line tool,output_modelcan also contain a name of a directory. In this case, the resulting OpenVINO IR files will be put into that directory with a base name of.xmland.binfiles matching the original model base name passed toovcas a parameter. For example, when callingovc your_model.onnx --output_model directory_name, filesdirectory_name/your_model.xmlanddirectory_name/your_model.binwill be created. Ifoutput_modelis not used, then the current directory is used as a destination directory.Note
openvino.save_modeldoes not support a directory foroutput_modelparameter value becauseopenvino.save_modelgets OpenVINO model object represented in a memory and there is no original model file name available for output file name generation. For the same reason,output_modelis a mandatory parameter foropenvino.save_model.verboseparameter activates extra diagnostics printed to the standard output. Use for debugging purposes in case there is an issue with the conversion and to collect information for better bug reporting to OpenVINO team.
Note
Weights sharing does not equally work for all the supported model formats. The value of this flag is considered as a hint for the conversion API, and actual sharing is used only if it is implemented and possible for a particular model representation.
You can always run ovc -h or ovc --help to recall all the supported
parameters for ovc.
Use ovc --version to check the version of OpenVINO package installed.