是否有任何方法可以将convert data-00000-of-00001
转换为Tensorflow Lite模型?文件结构是这样的
|-semantic_model.data-00000-of-00001
|-semantic_model.index
|-semantic_model.meta
使用TensorFlow版本:1.15] >>
下面的两个步骤将其转换为.tflite
模型。
1。使用.pb
您当前拥有的是模型checkpoint
(一个TensorFlow 1模型保存在3个文件中:.data ...,。meta和.index。可以根据需要对该模型进行进一步的训练)。您需要将其转换为frozen graph
(一个TensorFlow 1模型保存在单个.pb
文件中。该模型无法进一步训练,并且已针对推理/预测进行了优化)。
2。生成TensorFlow精简模型(.tflite
文件)
A。初始化TFLiteConverter:可以.from_frozen_graph
方式定义this API,可以添加的属性为here。要查找这些数组的名称,请在.pb
converter = tf.lite.TFLiteConverter.from_frozen_graph( graph_def_file='....path/to/frozen_graph.pb', input_arrays=..., output_arrays=...., input_shapes={'...' : [_, _,....]} )
B。可选:执行最简单的优化,称为post-training dynamic range quantization。您可以参考同一文档,了解其他类型的优化/量化方法。
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)