This document describes all available parameters for
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.
In most cases when it is required to convert a model the following simple syntax can be used:
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')
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 Python
openvino.convert_modelonly is intended to trace the model to obtain its graph representation. This parameter is crucial for converting PyTorch models and may sometimes be required for TensorFlow models. For more details, refer to the PyTorch Model Conversion or TensorFlow 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 by
ovcCLI tool and
openvino.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 to
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
Working with devices.
FP16 compression is sometimes used as the initial step for
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 value
Trueallows reusing memory with original weights. For models loaded in Python and then passed to
openvino.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 by
openvino.convert_model, file memory mapping is used to avoid extra memory allocation. When enabled, the original model cannot be destroyed (Python object cannot be deallocated and original model file cannot be deleted) for the whole lifetime of OpenVINO model. If it is not desired, set
ovc does not have
share_weights option and always uses sharing to reduce conversion time and consume less amount of memory during the conversion.
openvino.save_modelspecifies name for output
.xmlfile with the resulting OpenVINO IR. The accompanying
.binfile name will be generated automatically by replacing
.binextension. The value of
output_modelmust end with
ovccommand 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
.binfiles matching the original model base name passed to
ovcas a parameter. For example, when calling
ovc your_model.onnx --output_model directory_name, files
directory_name/your_model.binwill be created. If
output_modelis not used, then the current directory is used as a destination directory.
openvino.save_model does not support a directory for
output_model parameter value because
openvino.save_model gets 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_model is a mandatory parameter for
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.
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 --version to check the version of OpenVINO package installed.