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
262 stars 41 forks source link

Hand landmark model: AssertionError: Identity is not in graph #1

Closed geaxgx closed 3 years ago

geaxgx commented 3 years ago

1. OS Ubuntu 18.04

2. OS Architecture x86_64

4. Version of TensorFlow v2.4.1

9. Download URL for .tflite https://github.com/google/mediapipe/blob/master/mediapipe/modules/hand_landmark/hand_landmark.tflite

12. Issue Details

Hi PINTO, My goal is to convert the Mediapipe Hand landmark tflite model (the version of Nov 2020 which takes 224x224x3 frames as input) into a DepthAI blob file, so my first step is to use your tflite2tensorflow tool to convert the tflite into a pb file.

Here is the command line I use: tflite2tensorflow --model_path hand_landmark.tflite --flatc_path ./flatc --schema_path schema.fbs --output_pb True

Here is the begining and end of the output : op_types: ['ADD', 'ADD', 'ADD', 'ADD', 'ADD', 'ADD'] INFO: Replace the model generated by the old FlatBuffer with the new operator code. op_new_types: ['CONV_2D', 'DEPTHWISE_CONV_2D', 'ADD', 'RESHAPE', 'FULLY_CONNECTED', 'LOGISTIC'] num of ops: 64 [{'builtin_options': {'dilation_h_factor': 1, 'dilation_w_factor': 1, 'fused_activation_function': 'RELU6', 'padding': 'SAME', 'stride_h': 2, 'stride_w': 2}, 'builtin_options_type': 'Conv2DOptions', 'custom_options_format': 'FLEXBUFFERS', 'inputs': [0, 41, 5], 'opcode_index': 0, 'outputs': [106]}, .... TensorFlow/Keras model building process complete! saved_model / .pb output started ==================================================== WARNING:tensorflow:From /home/gx/env_tflite2tf/bin/tflite2tensorflow:2567: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.graph_util.convert_variables_to_constants WARNING:tensorflow:From /home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py:856: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version. Instructions for updating: Use tf.compat.v1.graph_util.extract_sub_graph ERROR: Identity is not in graph Traceback (most recent call last): File "/home/gx/env_tflite2tf/bin/tflite2tensorflow", line 2567, in main graph_def = tf.graph_util.convert_variables_to_constants( File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/util/deprecation.py", line 340, in new_func return func(*args, *kwargs) File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/framework/graph_util_impl.py", line 275, in convert_variables_to_constants ret = convert_to_constants.convert_variables_to_constants_from_session_graph( File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py", line 1143, in convert_variables_to_constants_from_session_graph converter_data=_SessionConverterData( File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py", line 856, in init graph_def = graph_util.extract_sub_graph(graph_def, output_node_names) File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/util/deprecation.py", line 340, in new_func return func(args, kwargs) File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/framework/graph_util_impl.py", line 208, in extract_sub_graph _assert_nodes_are_present(name_to_node, dest_nodes) File "/home/gx/env_tflite2tf/lib/python3.8/site-packages/tensorflow/python/framework/graph_util_impl.py", line 163, in _assert_nodes_are_present assert d in name_to_node, "%s is not in graph" % d AssertionError: Identity is not in graph**

Do you have an idea ? Identity is the name of one of the 3 model outputs.

Note that I have done the installation of Tensorflow Lite and Tensorflow as described in the README: pip install gdown gdown --id 1RWZmfFgtxm3muunv6BSf4yU29SKKFXIh chmod +x tflite_runtime-2.4.1-py3-none-any.whl pip install tflite_runtime-2.4.1-py3-none-any.whl pip install tensorflow==2.4.1 And I was able to successfully convert another model (the palm detection model).

PINTO0309 commented 3 years ago

I fixed the problem and upgraded the version. Please update the package and try again. The latest version is v1.1.2.

geaxgx commented 3 years ago

Thank you so much for your reactivity ! I upgraded and was able to successfully convert.