gpt4 book ai didi

java - 如何将操作添加到 Tensorflow Android 构建中

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:02 25 4
gpt4 key购买 nike

我正在尝试在 Android 上运行我的 Tensorflow 模型,所以我使用的是 nightly native build in here并关注 Android demo ,我已成功运行 Tensorflow Android 库并使用以下代码加载模型。

inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);

并且日志显示结果很好。

I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
I/TensorFlowInferenceInterface: Model load took 1007ms, TensorFlow version: 1.2.0-rc0
I/TensorFlowInferenceInterface: Successfully loaded model from 'file:///android_asset/model.pb'

但是,当我完成对所有输入节点的馈送

inferenceInterface.feed("input1", new int[]{1, 2, 3}, 1, 3);
inferenceInterface.feed("input2", new int[]{3}, 1);
inferenceInterface.feed("input3", new int[]{4}, 1);

然后调用run方法

inferenceInterface.run(new String[]{"output"});

Tensorflow 坏了说有些内核没有注册

E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[input1, input2, input3], outputs:[output]
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ...jnitest, PID: 16357
java.lang.RuntimeException: Unable to start activity ComponentInfo{...MainActivity}: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'LessEqual' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>

[[Node: .../LessEqual = LessEqual[T=DT_INT32](.../maximum_iterations, .../LessEqual/y)]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'LessEqual' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>

[[Node: dynamic_seq2seq/decoder/decoder_1/LessEqual = LessEqual[T=DT_INT32](.../maximum_iterations, .../LessEqual/y)]]
at org.tensorflow.Session.run(Native Method)
at org.tensorflow.Session.access$100(Session.java:48)
at org.tensorflow.Session$Runner.runHelper(Session.java:295)
at org.tensorflow.Session$Runner.run(Session.java:245)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:142)
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:111)
at ...jnitest.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
.. 9 more

我认为 int32 的“LessEqual”应该在 Tensorflow 中定义,但不应与 Tensorflow Android Lib 一起构建。

所以我的问题是如何在 Android 库构建中包含更多内核或以任何其他方式解决此问题,我们将不胜感激。

最佳答案

我推荐阅读这本免费电子书:Building Mobile Applications with TensorFlow

它有一个关于哪些操作在移动设备上可用?(第 33 页)的部分,它解释了如何为那些默认的操作内核将实现添加到构建被剥离用于移动构建。

仅供引用,这本电子书的作者是 Pete Warden(GitHubblog),他在 Google 工作,是 TensorFlow 的维护者之一。

关于java - 如何将操作添加到 Tensorflow Android 构建中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44938809/

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