编译Tensorflow_Android_Demo
1.修改build和gradle文件
2.修改build.gradle
, 把nativeBuildSystem的值改为none
3.下载模型文件并放到gradleBuild/downloads
下面,地址在download-models.gradle文件中 MODEL_URL+model
4.在工程目录下新建libs文件夹,添加libtensorflow_demo.so等文件
把libtensorflow_demo.so 文件复制过来。这样就不需要自己编译jni库了
5.报错:android Error:unsupported class file version 52.0
build文件修改为buildToolsVersion '27.0.3'
训练自己的模型移植到android
参考:https://blog.csdn.net/cxq234843654/article/details/71171293
1.训练自己的model保存为xx.pb文件
2.assets(new-->Folder-->Assets)文件夹下放模型xx.pb文件
libs文件夹下放tensorflow .so文件 和 jar文件(add as library) 官网下载:https://www.tensorflow.org/mobile/linking_libs
3.在android节点下添加soureSets,用于制定jniLibs的路径
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
在gradle.properties中添加下面一行
android.useDeprecatedNdk=true
4.建立模型调用类
5.报错及解决
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
添加
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
defaultConfig {
jackOptions {
enabled true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}