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

xception65をkeras(h5)に変換したい #124

Closed tatusya-suda closed 1 year ago

tatusya-suda commented 1 year ago

Issue Type

Others

OS

Windows

OS architecture

x86_64

Programming Language

Python

Framework

TensorFlow

Download URL for ONNX / OpenVINO IR

https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md

Convert Script

!source /opt/intel/openvino_2021/bin/setupvars.sh && pb_to_saved_model \ --pb_file_path frozen_inference_graph.pb \ --inputs sub_2:0 \ --outputs ResizeBilinear_2:0

!source /opt/intel/openvino_2021/bin/setupvars.sh &&\ python3 /opt/intel/openvino_2021/deployment_tools/model_optimizer/mo.py \ --saved_model_dir saved_model_from_pb/ --output_dir model_saved --data_type FP32

Description

https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/model_zoo.md のxception65_coco_voc_trainaug(.pb)をkeras(h5)に変換したいです。 しかし、openvino2tensorflowを使用して変換するときにpickleエラーが起きます。

環境はpython=3.8,tensorflow=2.5です。

変換ルートはpbからsaved_modelに変換したあと、IR形式に変換しています。

Relevant Log Output

TypeError: can't pickle module objects

Source code for simple inference testing code

No response

PINTO0309 commented 1 year ago
  1. Please let me know why you want to convert to .h5. This is a deprecated format at this time. saved_model should be sufficient for your needs.
  2. Is this the model you are converting to? deeplabv3_pascal_train_aug_2018_01_04.tar.gz image
  3. Your specification of the name of the input/output layer in your .pb is incorrect.
    pb_to_saved_model \
    --pb_file_path frozen_inference_graph.pb \
    --inputs ImageTensor:0 \
    --outputs SemanticPredictions:0

    image

saved_model_to_tflite \
--saved_model_dir_path saved_model_from_pb \
--input_shape [1,513,513,3] \
--model_output_dir_path saved_model \
--output_no_quant_float32_tflite

image

cp saved_model/model_float32.tflite .

tflite2tensorflow \
--model_path model_float32.tflite \
--flatc_path ../flatc \
--schema_path ../schema.fbs \
--output_pb \
--optimizing_for_openvino_and_myriad

image

saved_model_cli show --dir saved_model --all

2022-08-28 08:57:19.305342: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['ImageTensor'] tensor_info:
        dtype: DT_UINT8
        shape: (1, 513, 513, 3)
        name: ImageTensor:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['SemanticPredictions'] tensor_info:
        dtype: DT_INT64
        shape: (1, 513, 513)
        name: SemanticPredictions:0
  Method name is: tensorflow/serving/predict
tatusya-suda commented 1 year ago

1.keras modelに変換して、モデルの剪定を実施したいです。 剪定したモデルをtfliteに変換し、Androidへの実装を目指しています。 https://www.tensorflow.org/model_optimization/guide/pruning/pruning_with_keras

2.モデルはご指定のモデルです。

3.調べたときsub2とResizeBilinearを指定した例があったのでそちらで変換していました。ありがとうございます

PINTO0309 commented 1 year ago

If that is the case, then this question is not about openvino2tensorflow, but about how to use TensorFlow.

First, delete all unnecessary garbage processing in the range shown below.