PINTO0309 / tflite2tensorflow

Generate saved_model, tfjs, tf-trt, EdgeTPU, CoreML, quantized tflite, ONNX, OpenVINO, Myriad Inference Engine blob and .pb from .tflite. 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. Supports inverse quantization of INT8 quantization model.
https://qiita.com/PINTO
MIT License
266 stars 41 forks source link

Got error while converting magenta_arbitrary-image-stylization-v1-256_fp16_transfer_1.tflite to .h5 format #30

Closed yyuzhong closed 2 years ago

yyuzhong commented 2 years ago

Issue Type

Bug

OS

Ubuntu

OS architecture

x86_64

Programming Language

Python

Framework

TensorFlow

Download URL for tflite file

https://tfhub.dev/google/lite-model/magenta/arbitrary-image-stylization-v1-256/fp16/transfer/1

Convert Script

sudo docker run -it --rm \ -v pwd:/home/user/workdir \ ghcr.io/pinto0309/tflite2tensorflow:latest

tflite2tensorflow --model_path ./magenta_arbitrary-image-stylization-v1-256_fp16_transfer_1.tflite --flatc_path ../flatc --schema_path ../schema.fbs --output_no_quant_float32_tflite --output_dynamic_range_quant_tflite --output_weight_quant_tflite --output_float16_quant_tflite --output_integer_quant_tflite --string_formulas_for_normalization 'data / 255.0' --output_tfjs --output_coreml --output_onnx --onnx_opset 11 --output_openvino_and_myriad

openvino2tensorflow --model_path saved_model/openvino/FP32/saved_model.xml --output_h5

Description

I was trying to convert the saved_model or tflite model format into Keras model. The magenta_arbitrary-image-stylization-v1-256_fp16_prediction_1.tflite was good with your great help.

I got error again while trying magenta_arbitrary-image-stylization-v1-256_fp16_transfer_1.tflite by following the similar steps. Would you please help check it?

Thank you so much!

Relevant Log Output

Error log for openvino2tensorflow --model_path saved_model/openvino/FP32/saved_model.xml --output_h5

====================================================================================
layer_type: Sigmoid
layer_id: 473
input_layer0: layer_id=472: KerasTensor(type_spec=TensorSpec(shape=(1, 384, 384, 3), dtype=tf.float32, name=None), name='tf.math.add_72/Add:0', description="created by layer 'tf.math.add_72'")
tf_layers_dict: KerasTensor(type_spec=TensorSpec(shape=(1, 384, 384, 3), dtype=tf.float32, name=None), name='tf.math.sigmoid/Sigmoid:0', description="created by layer 'tf.math.sigmoid'")
====================================================================================
layer_type: Result
layer_id: 474
input_layer0: layer_id=473: KerasTensor(type_spec=TensorSpec(shape=(1, 384, 384, 3), dtype=tf.float32, name=None), name='tf.math.sigmoid/Sigmoid:0', description="created by layer 'tf.math.sigmoid'")
tf_layers_dict: KerasTensor(type_spec=TensorSpec(shape=(1, 384, 384, 3), dtype=tf.float32, name=None), name='tf.identity/Identity:0', description="created by layer 'tf.identity'")
====================================================================================
TensorFlow/Keras model building process complete!
.h5 output started ==================================================================
ERROR: cannot pickle 'module' object
Traceback (most recent call last):
  File "/usr/local/bin/openvino2tensorflow", line 7022, in convert
    model.save(f'{model_output_path}/model_float32.h5', include_optimizer=False, save_format='h5')
  File "/usr/local/lib/python3.8/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  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
All the conversion process is finished! =============================================

Source code for simple inference testing code

No response

PINTO0309 commented 2 years ago

Why do you ignore what I have answered? duplication: https://github.com/PINTO0309/openvino2tensorflow/issues/108#issuecomment-1137971705