Python tflite模型是如何实现的;conv“u actions”tflite“,由语音命令识别提供的android演示程序是否已转换?

Python tflite模型是如何实现的;conv“u actions”tflite“,由语音命令识别提供的android演示程序是否已转换?,python,tensorflow,speech-recognition,tensorflow-lite,Python,Tensorflow,Speech Recognition,Tensorflow Lite,我使用lite Converter在终端中将我的pb格式模型转换为tflite格式,但效果不佳 但是当我使用android demo提供的speech命令提供的tflite模型时,它运行得非常好。我想知道这个模型是如何转换的 使用上面的链接,我用下面的命令训练模型 (基本)unizen@admin:~/tensorflow/tensorflow/examples/speech_命令$python train.py 在培训后保存模型时,我使用以下代码创建了冻结模型 (base) unizen@a

我使用lite Converter在终端中将我的
pb格式
模型转换为
tflite格式
,但效果不佳

但是当我使用android demo提供的
speech命令提供的
tflite模型时,它运行得非常好。我想知道这个模型是如何转换的

使用上面的链接,我用下面的命令训练模型

(基本)unizen@admin:~/tensorflow/tensorflow/examples/speech_命令$python train.py

在培训后保存模型时,我使用以下代码创建了冻结模型

(base) unizen@admin:~/tensorflow/tensorflow/examples/speech_commands$ python freeze.py \
--start_checkpoint=/tmp/speech_commands_train/conv.ckpt-18000 \
--output_file=/tmp/my_frozen_graph.pb
但是当我尝试将
.pb格式
转换为
tflite格式

(base) unizen@admin:~/tensorflow/tensorflow/examples/speech_commands$  tflite_convert \
--saved_model_dir  /home/unizen/Downloads/my_frozen_graph.pb \
--input_format TENSORFLOW_GRAPHDEF \
--input_arrays decoded_sample_data \
--input_shapes 16000,1 \
--output_arrays labels_softmax \
--output_format TFLITE \
--output_file /tmp/sprc.tflite \
--allow_custom_ops
错误是

(base) unizen@admin:~/tensorflow/tensorflow/examples/speech_commands$ python usage: tflite_convert [-h] --output_file OUTPUT_FILE
                      (--saved_model_dir SAVED_MODEL_DIR | --keras_model_file KERAS_MODEL_FILE)
tflite_convert: error: one of the arguments --saved_model_dir --keras_model_file is required.
请提供将冻结模型转换为tflite模型的解决方案

tflite_convert: error: one of the arguments --saved_model_dir --keras_model_file is required.
表示您正在使用tensorflow>=2.0.0。
自2.0.0以来不再使用冻结图(.pb),开发人员应将其模型保存为“保存的模型”或keras模型,因此
tflite\u convert
命令不再支持它。
但是,如果您安装tensorflow 1.15,您应该能够像这样对其进行转换:

tflite_convert
--output_file=/output.tflite
--graph_def_file /path/to/my_frozen_graph.pb \
--input_arrays decoded_sample_data,decoded_sample_data:1 \
--output_arrays labels_softmax \
--allow_custom_ops
或者,如果您不想安装tensorflow 1.15,只需使用python API和
tf.compat.v1

import tensorflow as tf

converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph("./conv_actions_frozen.pb", input_arrays=['decoded_sample_data', 'decoded_sample_data:1'], output_arrays=['labels_softmax'])
converter.allow_custom_ops=True
tflite_model = converter.convert()
open("output.tflite", "wb").write(model)
这个

表示您正在使用tensorflow>=2.0.0。
自2.0.0以来不再使用冻结图(.pb),开发人员应将其模型保存为“保存的模型”或keras模型,因此
tflite\u convert
命令不再支持它。
但是,如果您安装tensorflow 1.15,您应该能够像这样对其进行转换:

tflite_convert
--output_file=/output.tflite
--graph_def_file /path/to/my_frozen_graph.pb \
--input_arrays decoded_sample_data,decoded_sample_data:1 \
--output_arrays labels_softmax \
--allow_custom_ops
或者,如果您不想安装tensorflow 1.15,只需使用python API和
tf.compat.v1

import tensorflow as tf

converter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph("./conv_actions_frozen.pb", input_arrays=['decoded_sample_data', 'decoded_sample_data:1'], output_arrays=['labels_softmax'])
converter.allow_custom_ops=True
tflite_model = converter.convert()
open("output.tflite", "wb").write(model)

tflite\u convert的文档位于以下位置:。你能在开头不加“python”吗?我确实试过了。我确实在一开始没有添加python的情况下运行了代码。我在问题中错误地使用python发布了代码。但是,感谢您的回复。如果您提出了解决方案,请确实在此处发布tflite\u convert的文档:。你能在开头不加“python”吗?我确实试过了。我确实在一开始没有添加python的情况下运行了代码。我在问题中错误地使用了python。但是,感谢您的回复。如果您提出了解决方案,请在这里发布。感谢您的回答,它正在工作。我在另一个问题(#59443695)中看到了冻结模型(conv#u actions_freezed.pb)文件是如何创建的,您的回答是它是由“旧示例android代码()”创建的。你知道除了旧的android代码示例中的10个单词外,我们如何训练更多的单词(比如0到9个)?是的,你可以!我已经做到了这一点,并训练了一点姓名识别能力。我要提到的是。简而言之:使用train.py训练音频数据,使用freeze.py冻结图形,并使用我的帖子中的上述代码将其转换为tflite。根据您的要求,我会将您想要训练的每个单词记录50-100次(不确定是否正确,我已将每个单词记录15次,并执行meh)。请确保您正在录制的音频是wav、1s长、16000Hz和单声道。抱歉,如果这与新旧版本有点混淆:D但是我上面评论中转换的模型将适用于新的android代码示例,但不适用于旧的android示例,因为旧的android示例不适用于tflite模型。我发布的培训文档用于培训旧模型,该模型在转换为tflite时可与新的android代码一起工作。为了清楚起见:-旧的android示例:->使用旧示例中的正常模型-新的android示例:->使用从旧示例中转换的tflite模型感谢您的回答,它正在工作。我在另一个问题(#59443695)中看到了冻结模型(conv#u actions_freezed.pb)文件是如何创建的,您的回答是它是由“旧示例android代码()”创建的。你知道除了旧的android代码示例中的10个单词外,我们如何训练更多的单词(比如0到9个)?是的,你可以!我已经做到了这一点,并训练了一点姓名识别能力。我要提到的是。简而言之:使用train.py训练音频数据,使用freeze.py冻结图形,并使用我的帖子中的上述代码将其转换为tflite。根据您的要求,我会将您想要训练的每个单词记录50-100次(不确定是否正确,我已将每个单词记录15次,并执行meh)。请确保您正在录制的音频是wav、1s长、16000Hz和单声道。抱歉,如果这与新旧版本有点混淆:D但是我上面评论中转换的模型将适用于新的android代码示例,但不适用于旧的android示例,因为旧的android示例不适用于tflite模型。我发布的培训文档用于培训旧模型,该模型在转换为tflite时可与新的android代码一起工作。为了清楚起见:-旧的android示例:->使用旧示例中的普通模型-新的android示例:->使用从旧示例中转换的tflite模型