【发布时间】:2017-10-27 02:54:33
【问题描述】:
我想在 Android-Studio 上使用 TensorFlow 图。
首先,我可以导入 org.tensorflow.contrib.android.TensorFlowInferenceInterface。但我无法创建实例。
这是 MainActivity.java。
package com.example.maguro.mnist_beginner;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;
public class MainActivity extends AppCompatActivity {
static{
System.loadLibrary("tensorflow_inference");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TensorFlowInferenceInterface inferenceInterface = new TensorFlowInferenceInterface();
}
}
错误点是最后的描述。
TensorFlowInferenceInterface inferenceInterface = new TensorFlowInferenceInterface();
错误提示“无法解析构造函数“TensorFlowInferenceInterface();”。
虽然我参考了 2 个主页,但我收到了这个错误。
http://docs.fabo.io/tensorflow/android/run.html
https://qiita.com/ohisama@github/items/f2fdd384a5e305462a79
我编辑了 2 个文件。“settings.gradle”和“app/build.gradle”
这是settings.gradle。
include ':app',':TensorFlow-Android-Inference'
findProject(":TensorFlow-Android-Inference").projectDir = new File("/home/maguro/tensorflow/tensorflow/contrib/android/cmake")
这里是 app/build.gradle。
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.maguro.mnist_beginner"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets{
main{
jniLibs.srcDirs = ['libs']
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
debugCompile project(path:':TensorFlow-Android-Inference',configuration:'debug')
releaseCompile project(path:':TensorFlow-Android-Inference',configuration:'release')
}
------我的环境------
操作系统:Ubuntu 14.04 LTS
Tensorflow:将 Anaconda 用于 python3.6 的 GPU
Android-Studio:2.3.3
CUDA 工具包:8.0
cuDNN:6.0
我英语不好。
如果我说了一些粗鲁的话,我很抱歉。
请帮帮我。
【问题讨论】:
-
你的项目中有 libtensorflow_inference.so 吗?
-
是的,我创建了包含 app/src/main/assets/libtensorflow_inference.so 的目录。
-
抱歉,我错过了之前的评论。我创建了具有 app/libs/libandroid_tensorflow_inference.java.jar 和 app/libs/arm64-v8a/libtensorflow_inference.so 的目录。
标签: java android android-studio tensorflow