Python 将-00000-of-00001文件的数据转换为Tensorflow Lite

Python 将-00000-of-00001文件的数据转换为Tensorflow Lite,python,tensorflow,tensorflow-lite,Python,Tensorflow,Tensorflow Lite,是否有任何方法将数据-00000-of-00001转换为Tensorflow Lite模型? 文件结构如下所示 |-semantic_model.data-00000-of-00001 |-semantic_model.index |-semantic_model.meta 使用TensorFlow版本:1.15 以下两个步骤将其转换为.tflite模型 1。使用 您当前拥有的是modelcheckpoint(TensorFlow 1模型保存在3个文件中:.data…,.meta和.in

是否有任何方法将数据-00000-of-00001转换为Tensorflow Lite模型? 文件结构如下所示

 |-semantic_model.data-00000-of-00001
 |-semantic_model.index
 |-semantic_model.meta
使用TensorFlow版本:1.15

以下两个步骤将其转换为
.tflite
模型

1。使用

您当前拥有的是model
checkpoint
(TensorFlow 1模型保存在3个文件中:.data…,.meta和.index。如果需要,可以进一步培训此模型)。您需要将其转换为
冻结图
(TensorFlow 1模型保存在单个
.pb
文件中。此模型无法进一步训练,并针对推理/预测进行了优化)

2。生成TensorFlow lite模型(
.tflite
文件)

A.初始化TFLiteConverter:from\u from\u freezed\u graphAPI可以通过这种方式定义,并且可以添加的属性是。要查找这些数组的名称,请在中可视化
.pb
文件

B.可选:执行最简单的优化,称为。对于其他类型的优化/量化方法,您可以参考同一文档

converter.optimizations = [tf.lite.Optimize.DEFAULT]
C.将其转换为
.tflite
文件并保存

tflite_model = converter.convert()

tflite_model_size = open('model.tflite', 'wb').write(tflite_model)
print('TFLite Model is %d bytes' % tflite_model_size)

你用什么tensorflow版本将模型保存到这些文件中?我从这个网站下载了这个ML数据()谢谢你的回答。我被第二步卡住了。如何将冻结的图形转换为tflite?我已经更新了上面的代码。您需要在TF1.x中使用
tf.compat.v1.lite.TFLiteConverter.from_freezed_graph
,在TF2.x中使用
tf.lite.TFLiteConverter.from_freezed_graph
,将冻结的图形加载到TFLiteConverter中。这对你有用吗?你能发布更多关于你所面临问题的细节吗?
tflite_model = converter.convert()

tflite_model_size = open('model.tflite', 'wb').write(tflite_model)
print('TFLite Model is %d bytes' % tflite_model_size)