将save_model.pb转换为model.tflite

问题描述

Tensorflow版本:2.2.0

操作系统:Windows 10

我正在尝试将saved_model.pb转换为tflite文件。

这是我正在运行的代码:

import tensorflow as tf

# Convert
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir='C:\Data\TFOD\models\ssd_mobilenet_v2_quantized')
tflite_model = converter.convert()


fo = open("model.tflite","wb")
fo.write(tflite_model)
fo.close

此代码在转换时给出错误:

  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\convert.py",line 196,in toco_convert_protos
    model_str = wrap_toco.wrapped_toco_convert(model_flags_str,File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\wrap_toco.py",line 32,in wrapped_toco_convert
    return _pywrap_toco_api.TocoConvert(
Exception: <unknown>:0: error: loc("Func/StatefulPartitionedCall/input/_0"): requires all operands and results to have compatible element types
<unknown>:0: note: loc("Func/StatefulPartitionedCall/input/_0"): see current operation: %1 = "tf.Identity"(%arg0) {device = ""} : (tensor<1x?x?x3x!tf.quint8>) -> tensor<1x?x?x3xui8>


During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "c:/Data/TFOD/convert.py",line 13,in <module>
    tflite_model = converter.convert()
  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\lite.py",line 1076,in convert
    return super(TFLiteConverterV2,self).convert()
  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\lite.py",line 899,in convert
    return super(TFLiteFrozenGraphConverterV2,File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\lite.py",line 629,in convert
    result = _toco_convert_impl(
  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\convert.py",line 569,in toco_convert_impl
    data = toco_convert_protos(
  File "C:\Users\Mr.Ace\AppData\Roaming\Python\Python38\site-packages\tensorflow\lite\python\convert.py",line 202,in toco_convert_protos
    raise ConverterError(str(e))
tensorflow.lite.python.convert.ConverterError: <unknown>:0: error: loc("Func/StatefulPartitionedCall/input/_0"): requires all operands and results to have compatible element types
<unknown>:0: note: loc("Func/StatefulPartitionedCall/input/_0"): see current operation: %1 = "tf.Identity"(%arg0) {device = ""} : (tensor<1x?x?x3x!tf.quint8>) -> tensor<1x?x?x3xui8>

解决方法

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

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

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