Tensorflow:SSD_mobilenet_v2_2 中的 TFLiteConverter(保存模型 -> TFLite)
Tensorflow: TFLiteConverter (Saved Model -> TFLite) in SSD_mobilenet_v2_2
我已经安装了tensorflow 2.3.1,我的ssd_mobile_net_v2_2是从https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2下载的。我想将此模型转换为 tf_lite 版本。我的代码是:
但是出现错误:
tensorflow.lite.python.convert.ConverterError: :0: 错误:loc("Func/StatefulPartitionedCall/input/_0"): 要求所有操作数和结果具有兼容的元素类型
:0: 注意:loc("Func/StatefulPartitionedCall/input/_0"): 查看当前操作:%1 = "tf.Identity"(%arg0) {device = ""} : (tensor<1x320x320x3x!tf.quint8> ) -> 张量<1x320x320x3xui8>
看来我需要设置输入数据类型,但我不知道该怎么做。
非常感谢您的回复。
我查看了 this 并发现了这个:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model("ssd_mobilenet_v2_2",signature_keys=['serving_default'])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
model = converter.convert()
open("converted_model.tflite", "wb").write(model)
我正在使用 tensorflow-nightly
我没有尝试过其他版本
解决方案来自:https://github.com/tensorflow/tensorflow/issues/42114#issuecomment-671593386
注:tf-nightly==2.4
我已经安装了tensorflow 2.3.1,我的ssd_mobile_net_v2_2是从https://tfhub.dev/tensorflow/ssd_mobilenet_v2/2下载的。我想将此模型转换为 tf_lite 版本。我的代码是:
但是出现错误:
tensorflow.lite.python.convert.ConverterError: :0: 错误:loc("Func/StatefulPartitionedCall/input/_0"): 要求所有操作数和结果具有兼容的元素类型
:0: 注意:loc("Func/StatefulPartitionedCall/input/_0"): 查看当前操作:%1 = "tf.Identity"(%arg0) {device = ""} : (tensor<1x320x320x3x!tf.quint8> ) -> 张量<1x320x320x3xui8>
看来我需要设置输入数据类型,但我不知道该怎么做。
非常感谢您的回复。
我查看了 this 并发现了这个:
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_saved_model("ssd_mobilenet_v2_2",signature_keys=['serving_default'])
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
model = converter.convert()
open("converted_model.tflite", "wb").write(model)
我正在使用 tensorflow-nightly
我没有尝试过其他版本
解决方案来自:https://github.com/tensorflow/tensorflow/issues/42114#issuecomment-671593386
注:tf-nightly==2.4