PINTO0309 / openvino2tensorflow

This script converts the ONNX/OpenVINO IR model to Tensorflow's saved_model, tflite, h5, tfjs, tftrt(TensorRT), CoreML, EdgeTPU, ONNX and pb. PyTorch (NCHW) -> ONNX (NCHW) -> OpenVINO (NCHW) -> openvino2tensorflow -> Tensorflow/Keras (NHWC/NCHW) -> TFLite (NHWC/NCHW). And the conversion from .pb to saved_model and from saved_model to .pb and from .pb to .tflite and saved_model to .tflite and saved_model to onnx. Support for building environments with Docker. It is possible to directly access the host PC GUI and the camera to verify the operation. NVIDIA GPU (dGPU) support. Intel iHD GPU (iGPU) support.
MIT License
334 stars 40 forks source link

Error of saving json during converting openvino model to tensorflow with parameter --output_weight_and_json #143

Closed alimagadovk closed 10 months ago

alimagadovk commented 10 months ago

Issue Type

Bug

OS

Ubuntu

OS architecture

x86_64

Programming Language

Python

Framework

OpenVINO, TensorFlow

Download URL for ONNX / OpenVINO IR

https://github.com/ShiqiYu/libfacedetection.train/tree/master/onnx

Convert Script

openvino2tensorflow --model_path model.xml --output_saved_model --output_weight_and_json

Description

I want convert an openvino-model to TF saved_model according to the documentation of https://github.com/PINTO0309/openvino2tensorflow repository.

Conversion pipeline: onnx->ir->tf_saved_model:

mo --input_model model_name.onnx

But when I use command: openvino2tensorflow --model_path model_name.xml --output_saved_model --output_weight_and_json

I get an error: ERROR: cannot pickle 'module' object, TypeError: cannot pickle 'module' object.

Relevant Log Output

ERROR: cannot pickle 'module' object
Traceback (most recent call last):
  File "/usr/local/bin/openvino2tensorflow", line 7156, in convert
    open(f'{model_output_path}/model_float32.json', 'w').write(model.to_json())
  File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 3086, in to_json
    model_config = self._updated_config()
  File "/usr/local/lib/python3.8/dist-packages/keras/engine/training.py", line 2954, in _updated_config
    config = self.get_config()
  File "/usr/local/lib/python3.8/dist-packages/keras/engine/functional.py", line 781, in get_config
    return copy.deepcopy(get_network_config(self, config=config))
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 205, in _deepcopy_list
    append(deepcopy(a, memo))
  File "/usr/lib/python3.8/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/python3.8/copy.py", line 296, in _reconstruct
    value = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.8/copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 210, in _deepcopy_tuple
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.8/copy.py", line 210, in <listcomp>
    y = [deepcopy(a, memo) for a in x]
  File "/usr/lib/python3.8/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: cannot pickle 'module' object

Source code for simple inference testing code

No response

PINTO0309 commented 10 months ago

I created another tool that can convert with high efficiency.

https://github.com/PINTO0309/onnx2tf

pip install onnx2tf -U

onnx2tf -i yunet_n_320_320.onnx -cotof -osd

image