Android:在安卓中使用TFLite模型
在安卓中使用TFLite不需要再進(jìn)行l(wèi)oadlibrary.
參考:基于Android搭建tensorflow lite,實(shí)現(xiàn)官網(wǎng)的Demo以及運(yùn)行自定義tensorflow模型(一)
1.安裝最新版AS,依據(jù)錯(cuò)誤提示安裝所需要的NDK和JDK,哪里錯(cuò)誤點(diǎn)哪里,幾個(gè)必要的組件安裝完畢之后便可以生成程序;
???? 安裝TensorFlow:https://tensorflow.google.cn/install/gpu
???? 默認(rèn)安裝了1.13,使用CUDA10; 所以,使用
pip install tensorflow-gpu==1.9.0?? 安裝適合cuda9的版本...不過這個(gè)TFLite沒有太大關(guān)系...
?
2.Git下載工程:https://github.com/amitshekhariitbhu/Android-TensorFlow-Lite-Example
About Android TensorFlow Lite Machine Learning Example
- This is an example project for integrating TensorFlow Lite into Android application
- This project include an example for object detection for an image taken from camera using TensorFlow Lite library.
- ?
3.在app的build.gradle中設(shè)置版本號(hào)
compileSdkVersion 27 defaultConfig {applicationId "com.amitshekhar.tflite"minSdkVersion 15targetSdkVersion 27versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"multiDexEnabled truendk {abiFilters "armeabi-v7a"abiFilters "armeabi"abiFilters "arm64-v8a"} } buildTypes { release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }進(jìn)行Synch,然后經(jīng)過一些列的NDK 版本安裝,排除錯(cuò)誤;
?
4.按鈕灰色問題
修改Gradle Scripts的文件:gradle-wrapper.properties
為classpath 'com.android.tools.build:gradle:3.2.0'?
5.運(yùn)行成功:
使用海信A6Pro雙面屏手機(jī),打開開發(fā)者模式,設(shè)置MTP傳輸模式,
否則會(huì)出現(xiàn):Unknown failure (at android.os.Binder.execTransact(Binder.java:731)) Error while Installing APKs 錯(cuò)誤!
測(cè)試,檢測(cè)到一個(gè)鼠標(biāo)
模型存放位置:Folder/app/src/main/assets/mobilenet_float_v1_224.tflite
?
6.使用OpenCV
使用Android studio,同時(shí)使用Android?camera2 和Android opencv34,出現(xiàn)編譯錯(cuò)誤:程序包android.hardware.camera2不存在。
解決方案如下:
在as中file->project structure->opencvlibrary340->修改compile sdk version 為21以上版本和 build tools version到更高版本,如下圖所示:
7.其他錯(cuò)誤
error: Split lib_slice_7_apk was defined multiple times
參考:https://blog.csdn.net/u010610691/article/details/77368536
在設(shè)置里取消Instant Run就可以正常的運(yùn)行了!
?
總結(jié)
以上是生活随笔為你收集整理的Android:在安卓中使用TFLite模型的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android studio run按钮
- 下一篇: Android: 生成安卓可使用的Tfl