# TensorFlow Lite影像辨識-蔡蕎宇 **將 TensorFlow Lite 添加到 Android 應用程序** 參照`https://codelabs.developers.google.com/codelabs/recognize-flowers-with-tensorflow-on-android/#4` *在訓練 TensorFlow Lite 模型前需下載並安裝AndroidStudio 4.1 或更高版本 參照`https://developer.android.com/studio` **下載TFLClassify-main專案** 參照`https://codelabs.developers.google.com/codelabs/recognize-flowers-with-tensorflow-on-android/#2` 點擊官網提供連結進行下載(TFLClassify-main) ![](https://i.imgur.com/eUrhxzx.png) 官網下載連結`https://github.com/hoitab/TFLClassify` 下載ZIP檔(TFLClassify-main) ![](https://i.imgur.com/dq61tbU.png) **使用Android Studio打開項目** 打開Android Studio後,從此彈出視窗中選擇“Open an Existing project”,接著開啟之前下載的TFLClassify-main ![](https://i.imgur.com/PDlr9wK.png) *注意:第一次打開會看到一個“Gradle Sync”視窗,詢問是否使用gradle包裝器,點擊“OK” ![](https://i.imgur.com/4Ipd8fp.png) 開啟TFLClassify-main後,在finish資料夾下找到並開啟MainActivity(主程式) ![](https://i.imgur.com/FH4YA5u.png) **將在colab上訓練好的學校各大樓影像辨識模型下載至電腦,並匯入Android Studio** 在左側欄位按右鍵點擊finish資料夾,然後依序點擊New> Other>TensorFlow Lite Model ![](https://i.imgur.com/0nmFTeb.png) 在model location選擇之前下載模型位置FlowerModel.tflite (模型需命名預設:FlowerModel.tflite) ![](https://i.imgur.com/dlJ0v3j.png) 匯入完成後會跳出以下畫面表示成功 ![](https://i.imgur.com/FuLmBiy.png) 輸出安裝檔(apk) ![](https://i.imgur.com/XxhXgF4.png) 表示輸出成功,點擊locate ![](https://i.imgur.com/WbyHLbY.png) 跳出視窗顯示apk檔位置(finish-debug.apk) ![](https://i.imgur.com/flKBwOe.png) 將安裝檔(apk)上傳至雲端硬碟,並從手機下載安裝 ![](https://i.imgur.com/xuOWQ6g.png) 執行軟體(手機畫面) ![](https://i.imgur.com/Aa0RHlq.png) ### #調整參數 **把手機畫面上方的tensorflow logo移除** 在finish資料夾下找到並開啟activity_main.xml ![](https://i.imgur.com/9fsUekB.png) 將39~43行註解 <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/tensorflow_lite_logo_description" android:src="@drawable/tfl2_logo" /> ![](https://i.imgur.com/M96MJLY.png) **將手機畫面下方的顯示百分比移除** 在finish資料夾下找到並開啟RecognitionViewModel.kt ![](https://i.imgur.com/Qi1fMhq.png) 第51行,將"%d"改為" "(第52行為原始程式) 51 val probabilityString = String.format(" ", confidence * 100.0f) 52 val probabilityString = System.out.printf("%d", confidence * 100.0f) ![](https://i.imgur.com/gelmAP5.png) **將顯示結果調整顯示1項最符合的結果**(預設為3) 在finish資料夾下找到並開啟MainActivity,將第53行改為private const val MAX_RESULT_DISPLAY = 1(數字擊代表顯示_項最符合的結果) ![](https://i.imgur.com/zcuoxGI.png) **使目前的執行緒暫停執行_毫秒(millisecond),傳入的參數為要暫停的時間長短** 在第34行加入Thread.sleep(5000);讓顯示出的結果停留5秒 ![](https://i.imgur.com/gLDFYqr.png)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up