CONVERT YOUR MODEL TO IR FORMAT

INSTALLATION

  • OpenVino Toolkit

    Download openvinotoolkit 2021.3 version : Link

    Instruction of installation : Link

  • Pytorch

  • Torchvision

  • Blobconverter

PYTORCH2ONNX

Create file pytorch2onnx.py and edit follow below :

  • Import packages :

    import sys
    import torch.onnx
    import torch
    import argparse
    from torch.autograd import Variable
    sys.path.append(".")
    import os
  • Define image shape :

    dummy_input = Variable(torch.randn(1, num_channels, h_image_input, w_image_input))
  • Load model :

    state_dict = torch.load(model_path,map_location='cpu' or 'gpu')
  • Export model :

    model.load_state_dict(state_dict)
    torch.onnx.export(model,               # model being run
                    dummy_input,                         # model input (or a tuple for multiple inputs)
                    "model_name_output.onnx",   # where to save the model (can be a file or file-like object)
                    #export_params=True,        # store the trained parameter weights inside the model file
                    opset_version=12,          # the ONNX version to export the model to
                    #do_constant_folding=True,  # whether to execute constant folding for optimization
                    #input_names = ['data'],   # the model's input names
                    #output_names = ['output'], # the model's output names
                    #dynamic_axes={'input' : {0 : 'batch_size'},    # variable length axes
                    #              'output' : {0 : 'batch_size'}})
      )

Detail for Instruction : Link

ONNX2IR

Complete installation openvinotoolkit, Cd ../openvino_2021/deployment_tools/model_optimizer and run :

python mo.py --input_model <path your Model.onnx> --input_shape [1, num_channels, h_image_input, w_image_input] --output_dir <path folder for your Model.bin and Model.xml>

IR2BLOB

  • Using online converter : Link

    Choose openvino version (default 2021.3 version), next step choose OpenVino Model then upload Model.bin and Model.xml

  • Or using package blobconverter : Link

Documentation

Documentation

Example

README_Example.md

GitHub

View Github