YOLO Usage
Notes
- EC YOLOv8 requires EC Android 10.15.0+
- EC Android integrates Tencent/ncnn optimized for mobile devices
- ncnn supports YOLOv5–YOLOv8; this guide uses YOLOv8 for training, inference, and detection
- YOLOv8 official site https://docs.ultralytics.com/modes/train/
- YOLO Demo download: Resources, cloud drive
YOLO Resources→YOLODemo.zip
Install & Train Model
- YOLO training uses Python — download Anaconda
- Download https://www.anaconda.com/download
- Tsinghua mirror: https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2024.06-1-Windows-x86_64.exe
- More Anaconda info: https://blog.csdn.net/ddafei/article/details/140326536
Install Software
- After installing Anaconda, create a virtual environment
- Click Create, name it yolotest (or other name), Python 3.8.19, Create
- Click green triangle on yolotest → Open Terminal
- Terminal prompt should show (yolotest)
Configure Environment
- Install Python packages in terminal:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
# yolo 0.3.1
# Latest: pip install yolo
pip install yolo==0.3.1
# ultralytics 8.2.79
# Latest: pip install ultralytics
pip install ultralytics==8.2.79
pip install ncnn==1.0.20240410
pip install labelimg
# Finally: pip list
- yolo, ultralytics installed
- Run
yoloin terminal to verify
- Run
labelimgto open annotation tool
Create Training Directory
- Create folder e.g.
yolotrainon E: drive - Under
yolotrain:labels/,images/; underimages/:test,train,val; underlabels/:train,val - Structure:
- Put same training images in
images/train,images/val, andimages/test(copy files) labels/trainandlabels/valhold labelimg annotation files
Annotate Data
- Put images in images/train, copy to images/val and images/test
- Run labelimg from configured terminal
- Open Dir → images/train (e.g. E:/yolotest/images/train)
- Change Save Dir → labels/train (e.g. E:/yolotest/labels/train)
- Set format to YOLO via Save format button
- Annotate
- Example: Like and Comment buttons on a short-video app
- Right-click → Create RectBox or click left Create RectBox
- Draw box on Like area, class name aixin, OK — used in API calls later
- Draw box on Comment, class pinglun, OK
- Save, Next Image for next image
- labels/train gets
classes.txtand per-image.txtfiles
- Copy labels/train to labels/val for validation
Train Model
- In yolotrain, create aixin.yaml:
path: E:/yolotrain
train: images/train
val: images/val
test: images/test
nc: 2
names: ["aixin","pinglun"]
-
Parameters:
-
path: training root (adjust drive/path)
-
train, val, test: image folders relative to path
-
nc: number of classes (2 here)
-
names: class names from labelimg — order matters
-
Train in cmd:
e:/thencd yolotrain -
Training command (pick one):
yolo detect train data=e:/yolotrain/aixin.yaml model=e:/yolotrain/yolov8s.pt imgsz=640
yolo detect train data=e:/yolotrain/aixin.yaml model=e:/yolotrain/yolov8s.pt epochs=100 imgsz=640
- Downloads
yolov8s.pt— if fail, get from demo zip or https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt
- Training in progress
- Done — Results saved path varies; example
runs/detect/trainunder E:/yolotrain
- Find
best.ptand annotated result images in output folder
Validate Model
- Validate on images:
yolo detect val data=e:/yolotrain/aixin.yaml model=e:/yolotrain/runs/detect/train/weights/best.pt
- Check Results saved path for annotated images
Export ONNX Model
- Export trained
.ptto ONNX for EC API
yolo export model=e:/yolotrain/runs/detect/train/weights/best.pt format=onnx
export successshows path — copy.onnxto phone/sdcard/(or other path)- Initialize with
yolov8Api.newYolov8Onxx; other API calls are the same
Export NCNN Model
- Export to ncnn for EC
yolo export model=e:/yolotrain/runs/detect/train/weights/best.pt format=ncnn
- Downloads
pnnx— use demopnnx-20240819-windows.zipin e:/yolotrain/ if download fails - Match filename in error screenshot or download manually
- Output has
model.ncnn.paramandmodel.ncnn.bin— copy both to phone sdcard
- Initialize with
yolov8Api.newYolov8for ncnn
API Usage
- Put trained model on phone
/sdcard/(or other path) - See YOLOv8 API Module
GPU
CONDA Virtual Environment Error
- Cannot select Python version when creating env — often network; switch to Tsinghua mirror
-
- Click channels
-
- Remove default channels
-
- Add Tsinghua channels (Enter after each)
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
-
- Click Update channels
Arial.ttf Download Error
- Download Arial.ttf
- Place in
C:\Users\Administrator\AppData\Roaming\UltralyticsasArial.ttf(Administrator= your Windows username)