This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
products:sbc:vim4:npu:demos:yolov8n [2024/01/04 04:51] louis |
products:sbc:vim4:npu:demos:yolov8n [2025/06/12 05:39] (current) louis |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ~~tag> NPU YOLO OpenCV VIM4 ~~ | ~~tag> NPU YOLO OpenCV VIM4 ~~ | ||
| + | |||
| + | **Doc for version ddk-3.4.7.7** | ||
| ====== YOLOv8n OpenCV VIM4 Demo - 2 ====== | ====== YOLOv8n OpenCV VIM4 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 VIM4. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | **Inference speed test**: USB camera about **150ms** per frame. | ||
| + | |||
| ===== Get Source Code ===== | ===== Get Source Code ===== | ||
| Line 12: | Line 25: | ||
| ``` | ``` | ||
| - | Refer '' | + | Refer '' |
| ===== Convert Model ===== | ===== Convert Model ===== | ||
| Line 20: | Line 33: | ||
| Follow Docker official documentation to install Docker: [[https:// | Follow Docker official documentation to install Docker: [[https:// | ||
| - | Then fetch the prebuilt NPU Docker | + | Follow |
| ```shell | ```shell | ||
| - | $ docker pull yanwyb/npu:v1 | + | docker pull numbqq/npu-vim4 |
| - | $ docker run -it --name | + | |
| - | -v / | + | |
| - | -v / | + | |
| - | yanwyb/ | + | |
| ``` | ``` | ||
| ==== Get Model Conversion Tools ==== | ==== Get Model Conversion Tools ==== | ||
| - | Get source [[gl> | + | Get source [[gh> |
| ```shell | ```shell | ||
| - | $ git clone https://gitlab.com/ | + | $ git lfs install |
| + | $ git lfs clone https://github.com/ | ||
| + | $ cd vim4_npu_sdk | ||
| + | $ ls | ||
| + | adla-toolkit-binary | ||
| ``` | ``` | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | <WRAP important> | ||
| + | If your kernel is older than 241129, please use branch npu-ddk-1.7.5.5. | ||
| + | </ | ||
| ==== Convert ==== | ==== Convert ==== | ||
| Line 42: | Line 63: | ||
| After training model, modify '' | After training model, modify '' | ||
| - | ```diff | + | ```diff head.py |
| diff --git a/ | diff --git a/ | ||
| index 0b02eb3..0a6e43a 100644 | index 0b02eb3..0a6e43a 100644 | ||
| Line 66: | Line 87: | ||
| + dfl = self.cv2[i](x[i]).contiguous() | + dfl = self.cv2[i](x[i]).contiguous() | ||
| + cls = self.cv3[i](x[i]).contiguous() | + cls = self.cv3[i](x[i]).contiguous() | ||
| - | + | + | + results.append(torch.cat([cls, |
| - | + # results.append(torch.cat([cls, | + | |
| + return tuple(results) | + return tuple(results) | ||
| + | + | ||
| ``` | ``` | ||
| + | |||
| + | <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 83: | Line 107: | ||
| $ python export.py | $ python export.py | ||
| ``` | ``` | ||
| + | |||
| + | <WRAP important> | ||
| + | Use [[https:// | ||
| + | |||
| + | {{: | ||
| + | </ | ||
| Enter '' | Enter '' | ||
| Line 103: | Line 133: | ||
| --input-shapes | --input-shapes | ||
| --dtypes " | --dtypes " | ||
| - | | + | --quantize-dtype |
| - | --inference-output-type float32 \ | + | |
| - | | + | |
| --channel-mean-value " | --channel-mean-value " | ||
| + | --inference-input-type " | ||
| + | --inference-output-type " | ||
| --source-file dataset.txt | --source-file dataset.txt | ||
| - | --disable-per-channel False \ | ||
| - | --iterations 500 \ | ||
| --batch-size 1 --target-platform PRODUCT_PID0XA003 | --batch-size 1 --target-platform PRODUCT_PID0XA003 | ||
| ``` | ``` | ||
| - | |||
| - | <WRAP important > | ||
| - | Please prepare about 500 pictures for quantification. If the pictures size is smaller than model input size, please resize pictures to input size before quantification. | ||
| - | </ | ||
| Run '' | Run '' | ||
| Line 133: | Line 157: | ||
| ``` | ``` | ||
| - | <WRAP important > | + | <WRAP important> |
| - | If your kernel | + | If your kernel is older than 241129, please use version before |
| </ | </ | ||
| Line 159: | Line 183: | ||
| # Run | # Run | ||
| - | $ sudo ./yolov8n -m ../ | + | $ ./yolov8n -m ../ |
| ``` | ``` | ||
| Line 175: | Line 199: | ||
| # Run | # Run | ||
| - | $ sudo ./ | + | $ ./ |
| ``` | ``` | ||