gpt4 book ai didi

python - 语音命令android demo提供的tflite格式的模型如何转换?

转载 作者:行者123 更新时间:2023-12-03 14:55:49 24 4
gpt4 key购买 nike

我使用lite Converter将我的pb格式模型转换为tflite格式,并使用lite Interpreter运行这个模型,但是效果不好,报错是:

Traceback (most recent call last):
File "/home/yuan/anaconda3/envs/TFLite/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/home/yuan/tensorflow-master/tensorflow/examples/speech_commands/audio/audio_processor_lite.py", line 41, in run
self._interpreter.allocate_tensors()
File "/home/yuan/anaconda3/envs/TFLite/lib/python3.7/site-packages/tensorflow_core/lite/python/interpreter.py", line 198, in allocate_tensors
return self._interpreter.AllocateTensors()
File "/home/yuan/anaconda3/envs/TFLite/lib/python3.7/site-packages/tensorflow_core/lite/python/interpreter_wrapper/tensorflow_wrap_interpreter_wrapper.py", line 106, in AllocateTensors
return _tensorflow_wrap_interpreter_wrapper.InterpreterWrapper_AllocateTensors(self)
RuntimeError: Regular TensorFlow ops are not supported by this interpreter. Make sure you invoke the Flex delegate before inference.Node number 0 (FlexAudioSpectrogram) failed to prepare.


看起来 lite 还不支持 FlexAudioSpectrogram 操作。但是当我使用speech command android demo提供的tflite模型时,效果很好。所以我想知道这个模型是如何转换的?

最佳答案

我找到了答案。
allow_custom_ops=True您可以将模型转换为 tflite,它在 android 中就像一个魅力。

我查看了转换后的模型和 netron 中 android 示例附带的模型,它们看起来相同。因此,他或她似乎就是这样做的。

小更新:

在另一个使用 tensorflow (Mozilla DeepSpeech) 的语音项目的源代码中,我发现了以下关于 tflite 转换中的 AudioSpectrogram 和 Mfcc ops 的评论:

# AudioSpectrogram and Mfcc ops are custom but have built-in kernels in TFLite
converter.allow_custom_ops = True

关于python - 语音命令android demo提供的tflite格式的模型如何转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56682885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com