This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
products:sbc:vim3:npu:ksnn:demos:yolov8n [2023/12/22 03:41] louis created |
products:sbc:vim3:npu:ksnn:demos:yolov8n [2025/04/23 22:35] (current) louis |
||
---|---|---|---|
Line 1: | Line 1: | ||
~~tag> NPU YOLO KSNN VIM3 ~~ | ~~tag> NPU YOLO KSNN VIM3 ~~ | ||
- | ====== YOLOv8n KSNN Demo - 1 ====== | + | ====== YOLOv8n KSNN Demo - 2 ====== |
{{indexmenu_n> | {{indexmenu_n> | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | |||
+ | YOLOv8n is an object detection model. It uses bounding boxes to precisely draw each object in image. | ||
+ | |||
+ | Inference results on VIM3. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | **Inference speed test**: USB camera about **182ms** per frame. MIPI camera about **156ms** per frame. | ||
===== Train the model ===== | ===== Train the model ===== | ||
Line 13: | Line 23: | ||
``` | ``` | ||
- | Refer '' | + | Refer '' |
===== Convert the model ===== | ===== Convert the model ===== | ||
Line 20: | Line 30: | ||
```shell | ```shell | ||
- | $ git clone --recursive | + | $ git lfs install |
+ | $ git lfs clone https:// | ||
``` | ``` | ||
Line 34: | Line 45: | ||
After training the model, modify '' | After training the model, modify '' | ||
- | ```diff | + | ```diff |
diff --git a/ | diff --git a/ | ||
index 0b02eb3..0a6e43a 100644 | index 0b02eb3..0a6e43a 100644 | ||
Line 62: | Line 73: | ||
+ | + | ||
``` | ``` | ||
+ | |||
+ | <WRAP important> | ||
+ | If you pip-installed ultralytics package, you should modify in package. | ||
+ | </ | ||
Create a python file written as follows to export ONNX model. | Create a python file written as follows to export ONNX model. | ||
Line 74: | Line 89: | ||
$ python export.py | $ python export.py | ||
``` | ``` | ||
+ | |||
+ | <WRAP important> | ||
+ | Use [[https:// | ||
+ | |||
+ | {{: | ||
+ | </ | ||
Enter '' | Enter '' | ||
```shell | ```shell | ||
+ | # uint8 | ||
$ ./convert --model-name yolov8n \ | $ ./convert --model-name yolov8n \ | ||
--platform onnx \ | --platform onnx \ | ||
Line 84: | Line 106: | ||
--quantized-dtype asymmetric_affine \ | --quantized-dtype asymmetric_affine \ | ||
--source-files ./ | --source-files ./ | ||
+ | --batch-size 1 \ | ||
+ | --iterations 1 \ | ||
--kboard VIM3 --print-level 0 | --kboard VIM3 --print-level 0 | ||
``` | ``` | ||
- | If you use '' | + | <WRAP important> |
+ | Now KSNN only supports '' | ||
+ | </ | ||
+ | |||
+ | If you want to use more quantified images, please modify '' | ||
+ | |||
+ | If you use '' | ||
If run succeed, converted model and library will generate in '' | If run succeed, converted model and library will generate in '' | ||
+ | |||
+ | <WRAP important> | ||
+ | If your YOLOv8 model perform bad on board, please try quanfity model in int8 or int16. | ||
+ | ```shell | ||
+ | # int8 | ||
+ | $ ./convert --model-name yolov8n \ | ||
+ | --platform onnx \ | ||
+ | --model yolov8n.onnx \ | ||
+ | --mean-values '0 0 0 0.00392156' | ||
+ | --quantized-dtype dynamic_fixed_point \ | ||
+ | --qtype int8 \ | ||
+ | --source-files ./ | ||
+ | --batch-size 1 \ | ||
+ | --iterations 1 \ | ||
+ | --kboard VIM3 --print-level 0 | ||
+ | |||
+ | # int16 | ||
+ | $ ./convert --model-name yolov8n \ | ||
+ | --platform onnx \ | ||
+ | --model yolov8n.onnx \ | ||
+ | --mean-values '0 0 0 0.00392156' | ||
+ | --quantized-dtype dynamic_fixed_point \ | ||
+ | --qtype int16 \ | ||
+ | --source-files ./ | ||
+ | --batch-size 1 \ | ||
+ | --iterations 1 \ | ||
+ | --kboard VIM3 --print-level 0 | ||
+ | ``` | ||
+ | </ | ||
===== Run inference on the NPU by KSNN ===== | ===== Run inference on the NPU by KSNN ===== | ||
Line 112: | Line 171: | ||
Put '' | Put '' | ||
+ | |||
+ | If your model' | ||
+ | |||
+ | ```shell | ||
+ | LISTSIZE = classes number + 64 | ||
+ | ``` | ||
==== Picture input demo ==== | ==== Picture input demo ==== | ||
Line 121: | Line 186: | ||
=== Camera input demo === | === Camera input demo === | ||
+ | |||
+ | For USB camera. | ||
+ | |||
+ | ```shell | ||
+ | # usb | ||
+ | $ cd ksnn/ | ||
+ | $ python3 yolov8n-cap.py --model ./ | ||
+ | ``` | ||
+ | |||
+ | For MIPI camera, OpenCV do not support GSTREAMER by **pip install**. So you need to install OpenCV by **sudo apt install**. | ||
```shell | ```shell | ||
+ | # mipi | ||
+ | $ pip3 uninstall opencv-python numpy | ||
+ | $ sudo apt install python3-opencv | ||
+ | $ pip3 install numpy==1.23 | ||
$ cd ksnn/ | $ cd ksnn/ | ||
- | $ python3 yolov8n-cap.py --model ./ | + | $ python3 yolov8n-cap.py --model ./ |
``` | ``` | ||
- | '' | + | '' |