tensorflow - 将 tensorflow 2.0 估计器转换为 tensorflow lite
问题描述
导出我的 saved_model.pb 文件后,我想在 TfLite 中转换它。
我和这篇文章有同样的错误。所以我尝试了建议的答案:
import tensorflow as tf
export_dir = './saved/1587630121'
# Convert the model.
saved_model_obj = tf.saved_model.load(export_dir="saved/1587630121/")
concrete_func = saved_model_obj.signatures['serving_default']
#this line produce the error: ValueError: This converter can only convert a single
#ConcreteFunction. Converting multiple functions is under development. :
#converter = tf.lite.TFLiteConverter.from_saved_model(export_dir)
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
print(saved_model_obj.signatures.keys())
# converter.optimizations = [tf.lite.Optimize.DEFAULT]
#converter.experimental_new_converter = True
tflite_model = converter.convert()
但是,我有一个新错误:
打印输出:
keysView(_SignatureMap({'predict': <tensorflow.python.eager.wrap_function.WrappedFunction object at 0x7f6a9843cc90>,
'classification': <tensorflow.python.eager.wrap_function.WrappedFunction object at 0x7f6a981a6190>,
'regression': <tensorflow.python.eager.wrap_function.WrappedFunction object at 0x7f6a74f78190>,
'serving_default': <tensorflow.python.eager.wrap_function.WrappedFunction object at 0x7f6a74d020d0>}))
converter.convert() 上的输出错误:
Exception has occurred: ConverterError
2020-04-23 12:05:52.644550: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2020-04-23 12:05:52.644632: F tensorflow/lite/toco/import_tensorflow.cc:2690]
Check failed: status.ok()
Input_content string_val doesn't have the right dimensions for this string tensor
(while processing node 'head/AsString')
Fatal Python error: Aborted
WARNING:tensorflow:Issue encountered when serializing variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef.
Note this is a warning and probably safe to ignore.
to_proto not supported in EAGER mode.
以防万一,由于以下代码,我毫无问题地导出了我的 DNNclassifier 估计器:
serving_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(tf.feature_column.make_parse_example_spec(self.feature_columns))
export_path = self.model_trained.export_saved_model(export_dir, serving_input_fn)
我想知道我的错误是否是因为我的 .pb 文件导出错误,这可能吗?否则您有解决此错误的想法吗?
谢谢您的帮助。
解决方案
推荐阅读
- php - Composer 依赖冲突(带有包的项目)
- javascript - 如何解决将 select 的值传递给服务器的问题?
- c# - 在使用对象时从一种实现类型转换为另一种实现类型是否可以?
- c++ - OpenGL C++(制作简单窗口时抛出错误)
- java - 如何从android studio中的另一个包扩展类-java
- r - 查找模式并过滤起始位置
- transloadit - 估计 Transloadit 装配持续时间
- java - 不明白哪个数据类型是 name.gettext().tostring()
- python - 如果启用了张量相等,如何解决错误变量是不可散列的。相反,使用 tensor.experimental_ref() 作为键
- ruby-on-rails - 为什么我在 Rails 应用程序中的时间字段也显示日期?