袁明帅*_*袁明帅 6 python tensorflow tensorflow-lite
我使用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.
Run Code Online (Sandbox Code Playgroud)
看起来 lite 还不支持 FlexAudioSpectrogram 操作。但是当我使用speech command android demo提供的tflite模型时,效果很好。所以我想知道这个模型是如何转换的?
我找到了答案。使用 ,allow_custom_ops=True您可以将模型转换为 tflite,它在 Android 中就像一个魅力。
我查看了我转换后的模型和 netron 中 android 示例附带的模型,它们看起来相同。看来他或她就是这样成功的。
小更新:
在另一个使用tensorflow的语音项目(Mozilla DeepSpeech)的源代码中,我发现了以下关于tflite转换中的AudioSpectrogram和Mfcc操作的评论:
Run Code Online (Sandbox Code Playgroud)# AudioSpectrogram and Mfcc ops are custom but have built-in kernels in TFLite converter.allow_custom_ops = True
| 归档时间: |
|
| 查看次数: |
366 次 |
| 最近记录: |