加入 custom object 的model 到android 的APK 中.

A. prepare customer.pt

   訓練過程將來補寫

    1. 轉到tflite

    python export.py --weights custom.pt --include tflite --img 320 --data repeat.yaml

   2. 確定轉出來結果沒有跑掉

     python detect.py --weights custom-fp16.tflite --source 1_repeat.jpg

B. copy custom-fp16.tflite to assets 目錄

     ..main\android\app\src\main\assets

C. make project of android studio

    build bundle and APK

步驟結束, 但... 一如往常, 事情不會如此順利.

 

D.  須要改程式

     image

    1. DetectorFactory 的19 行附近

else if (modelFilename.equals("custom-fp16.tflite")) {
    labelFilename = "file:///android_asset/coco2.txt";
    isQuantized = false;
    inputSize = 320;
    output_width = new int[]{40, 20, 10};
    masks = new int[][]{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
    anchors = new int[]{
            10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
    };

copy 一套, 改紅字部分.

2. 在assets 放入 coco2.txt, 內容為 object names, 共有 n 個Obj, 就有n 行

3.

  Build --> make project 

  build bundle and APK

大功告成!!!

 

到這裡結果可能還是會出錯!!!

E. coco2.txt

  注意這個檔案內容, 只能有 n 行, 不能有多余的空白行在最後....

 

相關文章 : YOLO5 建立手機安卓(android) 的APK-tflite TensorFlow版本- 任性學習

 

 

arrow
arrow
    創作者介紹
    創作者 cianfen 的頭像
    cianfen

    cianfen的部落格

    cianfen 發表在 痞客邦 留言(0) 人氣()