This script converts the OpenVINO IR model to Tensorflow's saved_model, tflite, h5 and pb. in (NCHW) format
Project description
openvino2tensorflow
This script converts the OpenVINO IR model to Tensorflow's saved_model, tflite, h5 and pb.
Work in progress now.
I'm continuing to add more layers of support and bug fixes on a daily basis. If you have a model that you are having trouble converting, please share the .bin and .xml with the issue. I will try to convert as much as possible.
1. Environment
- TensorFlow v2.3.1
- OpenVINO 2021.1.110
- Python 3.6+
2. Use case
- PyTorch (NCHW) -> ONNX (NCHW) -> OpenVINO (NCHW) ->
- ->
openvino2tensorflow-> Tensorflow/Keras (NHWC) -> TFLite (NHWC) - ->
openvino2tensorflow-> Tensorflow/Keras (NHWC) -> TFJS (NHWC) - ->
openvino2tensorflow-> Tensorflow/Keras (NHWC) -> TF-TRT (NHWC) - ->
openvino2tensorflow-> Tensorflow/Keras (NHWC) -> EdgeTPU (NHWC) - ->
openvino2tensorflow-> Tensorflow/Keras (NHWC) -> CoreML (NHWC)
- ->
3. Supported Layers
Currently, only 4D tensors are supported as input tensors.
| No. | OpenVINO Layer | TF Layer | Remarks |
|---|---|---|---|
| 1 | Parameter | Input | Input (4D tensor only) |
| 2 | Const | Constant, Bias | |
| 3 | Convolution | Conv2D | |
| 4 | Add | Add | |
| 5 | ReLU | ReLU | |
| 6 | PReLU | PReLU | |
| 7 | MaxPool | MaxPool2D | |
| 8 | AvgPool | AveragePooling2D | |
| 9 | GroupConvolution | DepthwiseConv2D, Conv2D/Split/Concat | |
| 10 | ConvolutionBackpropData | Conv2DTranspose | |
| 11 | Concat | Concat | |
| 12 | Multiply | Multiply | |
| 13 | Tan | Tan | |
| 14 | Tanh | Tanh | |
| 15 | Elu | Elu | |
| 16 | Sigmoid | Sigmoid | |
| 17 | HardSigmoid | hard_sigmoid | |
| 18 | SoftPlus | SoftPlus | |
| 19 | Swish | Swish | You can replace swish and hard-swish with each other by using the "--replace_swish_and_hardswish" option |
| 20 | Interpolate | ResizeNearestNeighbor, ResizeBilinear | |
| 21 | ShapeOf | Shape | |
| 22 | Convert | Cast | |
| 23 | StridedSlice | Strided_Slice | WIP |
| 24 | Pad | Pad, MirrorPad | |
| 25 | Clamp | ReLU6, Clip | |
| 26 | TopK | ArgMax, top_k | |
| 27 | Transpose | Transpose | |
| 28 | Squeeze | Squeeze | |
| 29 | Unsqueeze | Identity, expand_dims | WIP |
| 30 | ReduceMean | reduce_mean | |
| 31 | ReduceMax | reduce_max | |
| 32 | ReduceMin | reduce_min | |
| 33 | ReduceSum | reduce_sum | |
| 34 | ReduceProd | reduce_prod | |
| 35 | Subtract | Subtract | |
| 36 | MatMul | MatMul | |
| 37 | Reshape | Reshape | |
| 38 | Range | Range | WIP |
| 39 | Exp | Exp | |
| 40 | Abs | Abs | |
| 41 | SoftMax | SoftMax | |
| 42 | Negative | Negative | |
| 43 | Maximum | Maximum | No broadcast |
| 44 | Minimum | Minimum | No broadcast |
| 45 | Acos | Acos | |
| 46 | Acosh | Acosh | |
| 47 | Asin | Asin | |
| 48 | Asinh | Asinh | |
| 49 | Atan | Atan | |
| 50 | Atanh | Atanh | |
| 51 | Ceiling | Ceil | |
| 52 | Cos | Cos | |
| 53 | Cosh | Cosh | |
| 54 | Gather | Gather | |
| 55 | Divide | Divide, FloorDiv | |
| 56 | Erf | Erf | |
| 57 | Floor | Floor | |
| 58 | FloorMod | FloorMod | |
| 59 | HSwish | HardSwish | x*ReLU6(x+3)*0.16666667, You can replace swish and hard-swish with each other by using the "--replace_swish_and_hardswish" option |
| 60 | Log | Log | |
| 61 | Power | Pow | No broadcast |
| 62 | Mish | Mish | x*Tanh(softplus(x)) |
| 63 | Selu | Selu | |
| 64 | Equal | equal | |
| 65 | NotEqual | not_equal | |
| 66 | Greater | greater | |
| 67 | GreaterEqual | greater_equal | |
| 68 | Less | less | |
| 69 | LessEqual | less_equal | |
| 70 | Select | Select | No broadcast |
| 71 | LogicalAnd | logical_and | |
| 72 | LogicalNot | logical_not | |
| 73 | LogicalOr | logical_or | |
| 74 | LogicalXor | logical_xor | |
| 75 | Result | Identity | Output |
4. Setup
To install using the Python Package Index (PyPI), use the following command.
pip install openvino2tensorflow --upgrade
To install with the latest source code of the main branch, use the following command.
pip install git+https://github.com/PINTO0309/openvino2tensorflow --upgrade
5. Usage
usage: openvino2tensorflow [-h] --model_path MODEL_PATH
[--model_output_path MODEL_OUTPUT_PATH]
[--output_saved_model OUTPUT_SAVED_MODEL]
[--output_h5 OUTPUT_H5]
[--output_weight_and_json OUTPUT_WEIGHT_AND_JSON]
[--output_pb OUTPUT_PB]
[--output_no_quant_float32_tflite OUTPUT_NO_QUANT_FLOAT32_TFLITE]
[--output_weight_quant_tflite OUTPUT_WEIGHT_QUANT_TFLITE]
[--output_float16_quant_tflite OUTPUT_FLOAT16_QUANT_TFLITE]
[--replace_swish_and_hardswish REPLACE_SWISH_AND_HARDSWISH]
[--debug]
[--debug_layer_number DEBUG_LAYER_NUMBER]
optional arguments:
-h, --help show this help message and exit
--model_path MODEL_PATH
input IR model path (.xml)
--model_output_path MODEL_OUTPUT_PATH
The output folder path of the converted model file
--output_saved_model OUTPUT_SAVED_MODEL
saved_model output switch
--output_h5 OUTPUT_H5
.h5 output switch
--output_weight_and_json OUTPUT_WEIGHT_AND_JSON
weight of h5 and json output switch
--output_pb OUTPUT_PB
.pb output switch
--output_no_quant_float32_tflite OUTPUT_NO_QUANT_FLOAT32_TFLITE
float32 tflite output switch
--output_weight_quant_tflite OUTPUT_WEIGHT_QUANT_TFLITE
weight quant tflite output switch
--output_float16_quant_tflite OUTPUT_FLOAT16_QUANT_TFLITE
float16 quant tflite output switch
--replace_swish_and_hardswish REPLACE_SWISH_AND_HARDSWISH
Replace swish and hard-swish with each other.
--debug debug mode switch
--debug_layer_number DEBUG_LAYER_NUMBER
The last layer number to output when debugging. Used
only when --debug=True.
usage: pb_to_saved_model [-h] --pb_file_path PB_FILE_PATH
--inputs INPUTS
--outputs OUTPUTS
[--model_output_path MODEL_OUTPUT_PATH]
optional arguments:
-h, --help show this help message and exit
--pb_file_path PB_FILE_PATH
Input .pb file path (.pb)
--inputs INPUTS (e.g.1) input:0,input:1,input:2 / (e.g.2)
images:0,input:0,param:0
--outputs OUTPUTS (e.g.1) output:0,output:1,output:2 / (e.g.2)
Identity:0,Identity:1,output:0
--model_output_path MODEL_OUTPUT_PATH
The output folder path of the converted model file
6. Execution sample
6-1. Conversion of OpenVINO IR to Tensorflow models
OutOfMemory may occur when converting to saved_model or h5 when the file size of the original model is large, please try the conversion to a pb file alone.
$ openvino2tensorflow \
--model_path=openvino/448x448/FP32/Resnet34_3inputs_448x448_20200609.xml \
--output_saved_model True \
--output_pb True \
--output_weight_quant_tflite True \
--output_float16_quant_tflite True \
--output_no_quant_float32_tflite True
6-2. Convert Protocol Buffer (.pb) to saved_model
This tool is useful if you want to check the internal structure of pb files, tflite files, .h5 files, coreml files and IR (.xml) files. https://lutzroeder.github.io/netron/
$ pb_to_saved_model \
--pb_file_path model_float32.pb \
--inputs inputs:0 \
--outputs Identity:0
6-3. Converts saved_model to OpenVINO IR
$ python3 ${INTEL_OPENVINO_DIR}/deployment_tools/model_optimizer/mo_tf.py \
--saved_model_dir saved_model \
--output_dir openvino/reverse
6-4. Checking the structure of saved_model
$ saved_model_cli show \
--dir saved_model \
--tag_set serve \
--signature_def serving_default
7. Output sample
8. Model Structure
https://digital-standard.com/threedpose/models/Resnet34_3inputs_448x448_20200609.onnx
| ONNX | OpenVINO | TFLite |
|---|---|---|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openvino2tensorflow-0.2.2.tar.gz.
File metadata
- Download URL: openvino2tensorflow-0.2.2.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69162944db4ca2fd1c5c5f797d4a75c76fa7877910f028d4817860cfcc823650
|
|
| MD5 |
360da1a05c47a308ebe9face16f31fb5
|
|
| BLAKE2b-256 |
59cd5b2687395c07387e87dd5aeb5380bc754b24c4ba4912fe46acf764a7a756
|
File details
Details for the file openvino2tensorflow-0.2.2-py3-none-any.whl.
File metadata
- Download URL: openvino2tensorflow-0.2.2-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33d5d707bc221ebdb51200f6af2710b0f2c5ce9dd3bd3c0dec4a7729eccc3c08
|
|
| MD5 |
8c3bc67aeb436a885df0e0b762457aa4
|
|
| BLAKE2b-256 |
b607e734143c4052e52f45c2b850ba79021898f890c331e1b1ea88faeb435f73
|