当我尝试将保存的模型转换为tflite模型时,会出现此错误,我不知道如何通过此步骤。我保存的_模型是针对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, 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.
任何帮助都将不胜感激
这似乎是2.6的一个问题,在夜间构建2.7中得到了解决
https://github.com/tensorflow/tensorflow/issues/35194#issuecomment-902376756
https://github.com/tensorflow/tensorflow/issues/35194#issuecomment-902376756
但是,我在2.7中遇到了不同的问题。一旦我解决了这些问题,我将编辑此答案
相关问题 更多 >
编程相关推荐