android - 在 TensorFlow Lite C API 中注册自定义算子
问题描述
我正在使用 C API 在 Android 上运行 tensorflow lite。我的模型需要RandomStandardNormal
最近在 tensorflow 中作为自定义操作原型实现的运算v2.4.0-rc0
符
TfLiteInterpreterOptionsAddCustomOp()
函数在tensorflow/lite/c/c_api_experimental.h中列出:
TFL_CAPI_EXPORT void TfLiteInterpreterOptionsAddCustomOp(
TfLiteInterpreterOptions* options, const char* name,
const TfLiteRegistration* registration, int32_t min_version,
int32_t max_version);
看这个例子&线程,我试图这样使用TfLiteInterpreterOptionsAddCustomOp
:
// create model and interpreter options
TfLiteModel *model = TfLiteModelCreateFromFile("path/to/model.tflite");
TfLiteInterpreterOptions* options = TfLiteInterpreterOptionsCreate();
// register custom ops
TfLiteInterpreterOptionsAddCustomOp(options, "RandomStandardNormal", Register_RANDOM_STANDARD_NORMAL(), 1, 1);
// create the interpreter
TfLiteInterpreter* interpreter = TfLiteInterpreterCreate(model, options);
TfLiteInterpreterAllocateTensors(interpreter);
我看到该Register_RANDOM_STANDARD_NORMAL()
函数是在tensorflow/lite/kernels/custom_ops_register.htflite::ops::custom
的C++ 命名空间中定义的。但是,当我尝试将它包含在我的 C 文件中时,编译器会抱怨,因为它是 C 中的未知类型。namespace
如何使用 tensorflow lite C API 注册自定义运算符?我是否需要使用 C++ 编译器才能将 C API 与此自定义运算符一起使用,因为它是在 C++ 中定义的?
注意:我//tensorflow/lite/kernels:custom_ops
在编译时包含在 bazel BUILD deps 中libtensorflowlite_c.so
解决方案
看起来这是通过以下解决方法在 Github 上回答的:
https://github.com/tensorflow/tensorflow/issues/44664#issuecomment-723310060
推荐阅读
- java - 使用 QueryDSL 对 Oracle 数据库进行高效分页
- jenkins - 詹金斯订书机请求失败,没有有效的面包屑
- css - CSS动画播放不流畅
- javascript - 使用完整日历模块在 Moodle 中使用 requirejs 找到彼此时遇到问题
- spring - 无法解析 OpenID 配置 spring boot (security) java.net.ConnectException: Connection denied: connect
- html - 如何使用 HTML、CSS 或/和 Bootstrap 获取 Gmail 中的邮箱列表?
- r - 用于汇总统计信息的动态仪表板和 R 中 DF 的选定/所有变量下拉列表
- autosar - 如何在 AUTOSAR 中配置 NVM?
- windows - 如何根据PowerShell中的条件删除文件
- python - RNG 技术的可移植性和可重复性