ValueError:无法解析模型:仅支持具有单个子图的模型,模型有 X 个子图

问题描述

当我尝试将我保存的模型转换为 tflite 模型时,我收到此错误,我不知道如何从这里过去。我的 saved_model 适用于 mobilenet_ssd_v2,我通过这个创建了它 gist

这是我使用的 Colab 代码

!pip install tf-nightly
#import tensorflow as tf
import tensorflow.compat.v2 as tf
tf.enable_v2_behavior()
tf.__version__

def representative_dataset():
    for _ in range(100):
      data = np.random.rand(1,244,3)
      yield [data.astype(np.uint8)]

saved_model_obj = tf.saved_model.load("/content/model/")
#print(saved_model_obj.signatures)
concrete_func = saved_model_obj.signatures['serving_default']
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func]) # path to the SavedModel directory
converter.experimental_new_converter = True
converter.representative_dataset = representative_dataset
converter.target_spec.supported_ops = [
  tf.lite.OpsSet.TFLITE_BUILTINS,# enable TensorFlow Lite ops.
  tf.lite.OpsSet.SELECT_TF_OPS,# enable TensorFlow ops.
  tf.lite.OpsSet.TFLITE_BUILTINS_INT8
]
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.inference_input_type = tf.uint8  # or tf.uint8
converter.inference_output_type = tf.uint8  # or tf.uint8

tflite_model = converter.convert()

# Save the model.
with open('model.tflite','wb') as f:
  f.write(tflite_model)

完全错误

RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/optimize/calibrator.py in __init__(self,model_content)
     57       self._calibrator = (
---> 58           _calibration_wrapper.CalibrationWrapper(model_content))
     59     except Exception as e:

RuntimeError: Only models with a single subgraph are supported,model had 11 subgraphs

During handling of the above exception,another exception occurred:

ValueError                                Traceback (most recent call last)
5 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/lite/python/optimize/calibrator.py in __init__(self,model_content)
     58           _calibration_wrapper.CalibrationWrapper(model_content))
     59     except Exception as e:
---> 60       raise ValueError("Failed to parse the model: %s." % e)
     61     if not self._calibrator:
     62       raise ValueError("Failed to parse the model.")

ValueError: Failed to parse the model: Only models with a single subgraph are supported,model had 11 subgraphs.

任何帮助将不胜感激!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...