0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

android用のYolov11物体検出モデルを学習(メモ)

Last updated at Posted at 2025-02-02

roboflowを用いたデータセットの準備

・roboflowを使用してアノテーション作成と水増しデータ作成
 →少ないデータであれば無料枠でできるため個人的におすすめ
  https://app.roboflow.com/
・以下参考
https://qiita.com/Y_R_/items/07ced51178b38f7b2bde
https://zenn.dev/nexis_r/articles/0f0ab8670af844

学習データの準備

・以下参考(ただし、roboflowを使うとアノテーションファイルなども自動で作成してくれるので便利)
https://qiita.com/ryuka0610/items/a47fd253708a98d3726c
・準備した学習データはGoogleドライブに保存しGoogle Colabから参照できるようにする。
https://www.kikagaku.co.jp/kikagaku-blog/google-colab-drive-mount/

Google Colabを用いたYolov11モデル学習

・ランタイムのタイプはGPUを指定する必要がある。

# 必要なライブラリをインポート
!pip install ultralytics
!pip install torch torchvision torchaudio --upgrade

#モデルの学習(model=yolo11n.yamlとすることで事前学習済みモデルを使用せずに学習できる模様)
!yolo train data=/content/drive/MyDrive/dataset/data.yaml model=yolo11n.yaml epochs=100 imgsz=1280

上記の実行が成功すると以下のYolov11のモデルが生成される。
/content/drive/MyDrive/dataset/runs/detect/train/weights/best.pt

Yolov11をTFLite形式にエクスポート

# 必要なライブラリをインポート(2025/1/31時点ではバージョンを以下に合わせないとエラーになった)
!pip install --upgrade onnx onnx-tf typeguard
!pip install tensorflow==2.16.1
!pip install tf-keras==2.16.0
!pip install ultralytics


from ultralytics import YOLO
# YOLOモデルの読み込み
model = YOLO("best.pt")

# TFLite形式にエクスポート(imgszは省略可能)
model.export(format="tflite", imgsz=(1280, 1280))

検証環境構築&検証

・以下参考。
・作成したTFLite形式のモデルをassetsに配置およびlabels.txtのラベル名を学習時のモデルに合わせて変更。
・Constants.ktのMODEL_PATHを作成したTFLite形式のモデル名に変更。
https://github.com/surendramaran/YOLOv8-TfLite-Object-Detector/tree/main/app/src/main/assets
https://github.com/surendramaran/YOLOv8-TfLite-Object-Detector/blob/main/app/src/main/java/com/surendramaran/yolov8tflite/Constants.kt
https://qiita.com/john-rocky/items/ee69f8a396655d739e4b

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?