Yolov5 TFLite — Inferencing in Mobile Devices

Learning Outcome:

Installation

git clone https://github.com/Techyhans/yolov5-portholes.git
cd yolov5
pip install -r requirements.txt

Train custom Yolov5 model

path: data/sample
train: train/images
val: valid/images
test: test/images
nc: 2
names: ['CoW', 'chanterelle']
python train.py --img 640 --batch 16 --epochs 300 --data sample/data.yaml --weights yolov5s.pt

Convert Pytorch (.pt) model file to TFLite (.tflite)

python export.py --weights best.pt --include tflite --tf-nms --agnostic-nms

Metadata Writer

"name": "ObjectDetector",
"description": "Identify which of a known set of objects might be present and provide information about their positions within the given image or a video stream."
python metadata_writer_v1.py --model_file best-fp16.tflite --label_file labels.txt
# Your model details here
model_path = ‘best-fp16.tflite’
label_path = ‘labels.txt’
model_meta.name = “Model name”
model_meta.description = (
“decription line …”
“decription line …”
)
python metadata_writer_v2.py

Detection

Github

Reference

About Author

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Draden Liang Han Sheng

Full Stack AI Application Development | Computer Vision | Deep Learning | Edge Devices