YOLO Application Guide#
Attention
YOLO deployment code uses the same single-camera dual-channel development pattern. Refer to single_model_example.md for the core application logic.
Overview#
K230 provides a unified wrapper for the YOLO family and supports YOLOv5, YOLOv8, and YOLO11. It covers four mainstream visual tasks:
image classification (
classify)object detection (
detect)instance segmentation (
segment)oriented object detection (
obb, supported by YOLOv8 and YOLO11)
Users can switch model types through parameters and choose the input mode according to the application scenario (video or image). Custom AI-frame resolutions are also supported so that model performance, speed, and accuracy can be tuned during deployment.
Model Conversion#
For model training and conversion to kmodel, refer to the official workflow in YOLO Battle Guide:
After following that guide, the generated YOLO kmodel files can be used directly with the functions and examples described on this page.
YOLO Support#
The YOLO source code is located at:
src/rtsmart/examples/ai/yolo
The code wraps the camera and display parts of AI inference, so the user mainly needs to obtain inference frames and pass them to the YOLO model interfaces.
Code Structure#
YOLO
├── cmake
├── src
│ ├── ai_base.cc
│ ├── ai_base.h
│ ├── main.cc
│ ├── pipeline.cc
│ ├── pipeline.h
│ ├── scoped_timing.hpp
│ ├── utils.cc
│ ├── utils.h
│ ├── yolo11.cc
│ ├── yolo11.h
│ ├── yolov5.cc
│ ├── yolov5.h
│ ├── yolov8.cc
│ ├── yolov8.h
│ └── CMakeLists.txt
├── utils
├── Makefile
├── CMakeLists.txt
└── build_app.sh
Code Notes#
File |
Purpose |
|---|---|
|
interfaces used during model inference |
|
implementation of the common inference wrapper |
|
timing helper for debugging |
|
media wrapper for display, video output, camera capture, OSD initialization, frame get/release/insert, and pipeline destruction |
|
implementation of the media wrapper |
|
helper interfaces for binary-file reading, image saving, preprocessing configuration, and shared utilities |
|
implementation of the helper functions |
|
YOLO11 initialization, preprocess, inference, postprocess, and draw interfaces |
|
YOLOv5 initialization, preprocess, inference, postprocess, and draw interfaces |
|
YOLOv8 initialization, preprocess, inference, postprocess, and draw interfaces |
|
main entry and application flow |
The utils directory contains example models and images used for board deployment, and build_app.sh is the build script.
Build#
Select Board and Build Application#
From the RTOS root:
make list-def
make ***_defconfig
make -j
Build Method 1#
After the code is ready, enter the directory containing build_app.sh and run:
./build_app.sh
The build intermediates are placed in build, and the deployment summary files are placed in k230_bin.
Build Method 2#
From the RTOS SDK root, run make menuconfig and enable:
RT-Smart UserSpace Examples Configuration
-> Enable build ai examples
-> Enable Build YOLO Programs
Then run:
make -j
This builds the deployment outputs directly into:
/sdcard/app/examples/ai/yolo
You can also enter the example directory and run:
make -j
This also supports incremental build and places outputs in k230_bin.
Runtime Parameters#
Parameter |
Default |
Description |
|---|---|---|
|
|
AI-frame width |
|
|
AI-frame height |
|
|
display mode: |
|
|
model type: |
|
|
task type: |
|
|
task mode: |
|
|
image path for image mode |
|
|
model path |
|
|
label file, one label per line |
|
|
confidence threshold |
|
|
NMS threshold |
|
|
mask threshold |
|
|
debug mode, |
Run Examples#
Flash the firmware first. See:
Then copy the generated .elf, kmodel, test images, and related files from k230_bin to CanMV/sdcard.
Connect to the board through a serial console. You can run yolo.elf -help to view the parameter list.
Video Inference#
# equivalent helper: ./video_run.sh
./yolo.elf -ai_frame_width 640 -ai_frame_height 360 -display_mode 0 -model_type yolov8 -task_type detect -task_mode video -kmodel_path yolov8n.kmodel -labels_txt_filepath coco_labels.txt -conf_thres 0.35 -nms_thres 0.65 -mask_thres 0.5 -debug_mode 0
Image Inference#
# equivalent helper: ./image_run.sh
./yolo.elf -model_type yolov8 -task_type detect -task_mode image -image_path test.jpg -kmodel_path yolov8n.kmodel -labels_txt_filepath coco_labels.txt -conf_thres 0.35 -nms_thres 0.65 -mask_thres 0.5 -debug_mode 0
During deployment, you can change the model, AI-frame resolution, task type, task mode, and thresholds as needed.
Notes#
Supported models:
yolov5,yolov8,yolo11Supported task types:
classify,detect,segment,obbSupported task modes:
video,imageSupported display modes:
LT9611,ST7701,HX8377For tuning, first adjust thresholds, then revisit quantization and input resolution
If the AI-frame resolution matches the model input resolution, runtime speed is usually better optimized
