【问题标题】:Tensorflow: TFLiteConverter (Saved Model -> TFLite) in SSD_mobilenet_v2_2Tensorflow:SSD_mobilenet_v2_2 中的 TFLiteConverter(保存的模型 -> TFLite)
【发布时间】:2021-02-12 03:19:24
【问题描述】:

我已经安装了 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: error: loc("Func/StatefulPartitionedCall/input/_0"): 要求所有操作数和结果具有兼容的元素类型 :0: 注意: loc("Func/StatefulPartitionedCall/input/_0"): 查看当前操作: %1 = "tf.Identity"(%arg0) {device = ""} : (tensor ) -> 张量

看来我需要设置输入数据类型,但我不知道该怎么做。

非常感谢您的回复。

【问题讨论】:

    标签: python tensorflow tensorflow-datasets tensorflow-lite


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      我查看了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 我没有尝试过其他版本

      【讨论】:

      • 感谢您的回复。但是您使用的 tf-nightly 版本是什么?我试过 tf-nightly==2.3.0.dev20200513 但错误显示:
      • 你能尝试运行我的代码吗?可能ssd_mobilenet模型是新的,会有很多不兼容的
      • 我有这个版本2.4.0-dev20200812。当我尝试你的代码时,我遇到了同样的错误。
      • 在转换后的 lite 模型中,input_shape 是什么?
      • 通过运行:input_shape = input_details[0]['shape'] print(input_shape)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多