【发布时间】:2018-09-12 04:49:09
【问题描述】:
我在我的 Android 应用程序中使用了一个训练模型(冻结图),该应用程序利用了 Tensorflow 的预制虹膜估计器示例,如以下链接所示:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/iris.py
我已经修改了 iris.py 以适应我的需要,并添加了一些语句来冻结图形,以便我将一个 .pb 文件放入我的 Android 应用程序的资产文件夹中。
为了在我的 Android 应用程序中使用 Tensorflow,我在我的 build.gradle (Module: app) 文件中添加了以下行(依赖项块中的最后一条语句)。
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'no.nordicsemi.android.support.v18:scanner:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'
implementation 'org.tensorflow:tensorflow-android:+'
}
有了我的冻结图,我正在通过执行以下语句来测试 Tensorflow 是否正在运行我的应用程序:
//testing tensorflow feature
TensorFlowInferenceInterface tfInterface = new
TensorFlowInferenceInterface(
getAssets(), "estimator_frozen_graph.pb");
Graph graph = tfInterface.graph();
Toast.makeText(ScanActivity.this, "Tensorflow Graph Init Success",
Toast.LENGTH_SHORT).show();
int[] inputValues = {1, 1, 121, 800, 300};
long rowDim = 1;
long columnDim = 5;
tfInterface.feed("dnn/input_from_feature_columns/input_layer/concat:0",
inputValues, rowDim, columnDim);
String[] outputNames = {"dnn/logits/BiasAdd:0"};
boolean logstats = false;
tfInterface.run(outputNames, logstats);
float[] outputs = new float[6];
tfInterface.fetch("dnn/logits/BiasAdd:0", outputs);
for(int i = 0; i<= outputs.length; i++)
{
System.out.println(outputs[i]);
}
当程序到达该行时:
tfInterface.run(outputNames, logstats);
Android Studio的logcat中出现如下错误信息:
Caused by: java.lang.IllegalArgumentException: No OpKernel was registered to support Op 'Iterator' with these attrs. Registered devices: [CPU], Registered kernels:
<no registered kernels>
[[Node: Iterator = Iterator[container="", output_shapes=[[?], [?], [?], [?], [?], [?]], output_types=[DT_INT64, DT_INT64, DT_INT64, DT_INT64, DT_INT64, DT_INT64], shared_name=""]()]]
at org.tensorflow.Session.run(Native Method)
我一直在寻找类似的问题和问题,但似乎找不到解决此问题的可行方法。
如果我需要添加任何信息以简化在此处获得帮助的过程,请告诉我。提前致谢。
【问题讨论】:
标签: java android python tensorflow tensorflow-estimator