Doc*_*ven 10 c++ python-3.x tensorflow tensorflow-lite
我有一个 TensorFlow 模型,我想将其转换为 tflite 模型,该模型将部署在 ARM64 平台上。
恰好是我的模型的两个操作(RandomStandardNormal、Softplus)似乎需要自定义实现。由于执行时间不是那么重要,我决定采用使用扩展运行时间的混合模型。我通过以下方式转换它:
graph_def_file = './model/frozen_model.pb'
inputs = ['eval_inputs']
outputs = ['model/y']
converter = tf.lite.TFLiteConverter.from_frozen_graph(graph_def_file, inputs, outputs)
converter.target_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
tflite_file_name = 'vae_' + str(tf.__version__) + '.tflite'
tflite_model = converter.convert()
open(tflite_file_name, 'wb').write(tflite_model)
Run Code Online (Sandbox Code Playgroud)
这奏效了,我最终得到了一个看似有效的 tflite 模型文件。每当我尝试使用解释器加载此模型时,都会收到错误消息(我使用 Python 还是 C++ API 都没有关系):
ERROR: Regular TensorFlow ops are not supported by this interpreter. Make sure you invoke the Flex delegate before inference.
ERROR: Node number 4 (FlexSoftplus) failed to prepare.
Run Code Online (Sandbox Code Playgroud)
我很难在 tf 网站上找到有关如何为这两个 API 调用 Flex 委托的文档。我偶然发现了一个头文件(“tensorflow/lite/delegates/flex/delegate_data.h”),它似乎与这个问题有关,但将它包含在我的 C++ 项目中会产生另一个错误:
In file included from /tensorflow/tensorflow/core/common_runtime/eager/context.h:28:0,
from /tensorflow/tensorflow/lite/delegates/flex/delegate_data.h:18,
from /tensorflow/tensorflow/lite/delegates/flex/delegate.h:19,
from demo.cpp:7:
/tensorflow/tensorflow/core/lib/core/status.h:23:10: fatal error: tensorflow/core/lib/core/error_codes.pb.h: No such file or directory
#include "tensorflow/core/lib/core/error_codes.pb.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
有没有人遇到并解决过这个问题?如果您有示例代码段,请分享链接!
小智 -1
根据https://www.tensorflow.org/lite/guide/ops_select#android_aar于 2019/9/25
Python 对“选择运算符”的支持正在积极开发中。
您可以使用 FlexDelegate 在 Android 中测试模型。我以同样的方式成功运行了我的模型。
| 归档时间: |
|
| 查看次数: |
5316 次 |
| 最近记录: |