Legacy Conversion API — OpenVINO™ documentation (original) (raw)

Note

This part of the documentation describes a legacy approach to model conversion. Starting with OpenVINO 2023.1, a simpler alternative API for model conversion is available: openvino.convert_model and OpenVINO Model Converter ovc CLI tool. Refer to Model preparation for more details. If you are still using openvino.tools.mo.convert_model or mo CLI tool, you can still refer to this documentation. However, consider checking the transition guide to learn how to migrate from the legacy conversion API to the new one. Depending on the model topology, the new API can be a better option for you.

To convert a model to OpenVINO model format (ov.Model), you can use the following command:

Python

from openvino.tools.mo import convert_model ov_model = convert_model(INPUT_MODEL)

CLI

mo --input_model INPUT_MODEL

If the out-of-the-box conversion (only the input_model parameter is specified) is not successful, use the parameters mentioned below to override input shapes and cut the model:

To get the full list of conversion parameters, run the following command:

Python

from openvino.tools.mo import convert_model ov_model = convert_model(help=True)

CLI

Examples of model conversion parameters#

Below is a list of separate examples for different frameworks and model conversion parameters:

  1. Launch model conversion for a TensorFlow MobileNet model in the binary protobuf format:
    Python
    from openvino.tools.mo import convert_model
    ov_model = convert_model("MobileNet.pb")
    CLI
    mo --input_model MobileNet.pb
    Launch model conversion for a TensorFlow BERT model in the SavedModel format with three inputs. Specify input shapes explicitly where the batch size and the sequence length equal 2 and 30 respectively:
    Python
    from openvino.tools.mo import convert_model
    ov_model = convert_model("BERT", input_shape=[[2,30],[2,30],[2,30]])
    CLI
    mo --saved_model_dir BERT --input_shape [2,30],[2,30],[2,30]
    For more information, refer to the Converting a TensorFlow Model guide.
  2. Launch model conversion for an ONNX OCR model and specify new output explicitly:
    Python
    from openvino.tools.mo import convert_model
    ov_model = convert_model("ocr.onnx", output="probabilities")
    CLI
    mo --input_model ocr.onnx --output probabilities
    For more information, refer to the Converting an ONNX Model guide.
    Note
    PyTorch models must be exported to the ONNX format before conversion into IR. More information can be found in Converting a PyTorch Model.
  3. Launch model conversion for a PaddlePaddle UNet model and apply mean-scale normalization to the input:
    Python
    from openvino.tools.mo import convert_model
    ov_model = convert_model("unet.pdmodel", mean_values=[123,117,104], scale=255)
    CLI
    mo --input_model unet.pdmodel --mean_values [123,117,104] --scale 255
    For more information, refer to the Converting a PaddlePaddle Model guide.