DEV Community

Ray
Ray

Posted on

YOLO V5 running on an Android phone Part 1(train model)

Kia Ora!
Recently in our AI project, we have been working on monitoring river heights using the Yolo algorithm. It sends an alert like a server when the river height exceeds a certain safe range.
Today I am bringing you a share on how to deploy the Yolo algorithm program using an Android phone

Image description

My main development environment is currently an M1 chip MAC, and I often encounter all kinds of bugs on Yolo v8 (but I already have a solution, I'll organize it and update it later), so for today's demo tutorial we're going to start with Yolo v5. I'd like to thank this YouTuber, whose video solved a very large number of problems for me:
https://www.youtube.com/watch?v=zs43IrWTzB0

I won't go over the steps to install Yolo v5, you can easily find their repository on Git Hub.
For labelling and processing the data I used: roboflow
This page is very user-friendly for all versions of Yolo support. There are also many open-source datasets available.

Use the dataset to train:



!python train.py --img 640 ---batch 16 --epochs 10 --data DataSet/data.yaml --weights yolov5s.pt


Enter fullscreen mode Exit fullscreen mode

Validate using the dataset:



!python detect.py --source DataSet/valid/images --weights runs/train/exp/weights/best.pt


Enter fullscreen mode Exit fullscreen mode

After completing the training, we need to export to the tflite format



!python export.py --weights runs/train/exp/weights/best.pt --include tflite


Enter fullscreen mode Exit fullscreen mode

This concludes our training of the model and I can't wait to try it out:



!python detect.py --source 0 --weights runs/train/exp/weights/best.pt


Enter fullscreen mode Exit fullscreen mode

Image description
This way we have our own model, and of course we are able to achieve better performance through various manipulations of the dataset during the training process.

Top comments (0)