Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:vim4:npu:demos:yolov8n

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
products:sbc:vim4:npu:demos:yolov8n [2023/09/18 01:52]
sravan [Build virtual environment]
products:sbc:vim4:npu:demos:yolov8n [2025/01/08 22:22] (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 ======
Line 12: Line 14:
 ``` ```
  
-Refer ''README.md'' to train a YOLOv8n model.+Refer ''README.md'' to train a YOLOv8n model. My version ''torch==1.10.1'' and ''ultralytics==8.0.86''.
  
 ===== Convert Model ===== ===== Convert Model =====
Line 20: Line 22:
 Follow Docker official documentation to install Docker: [[https://docs.docker.com/engine/install/ubuntu/|Install Docker Engine on Ubuntu]]. Follow Docker official documentation to install Docker: [[https://docs.docker.com/engine/install/ubuntu/|Install Docker Engine on Ubuntu]].
  
-Then fetch the prebuilt NPU Docker container and run it.+Follow the script below to get Docker image:
  
 ```shell ```shell
-docker pull yanwyb/npu:v1 +docker pull numbqq/npu-vim4
-$ docker run -it --name vim4-npu1 -v $(pwd):/home/khadas/npu \ +
- -v /etc/localtime:/etc/localtime:ro \ +
- -v /etc/timezone:/etc/timezone:ro \ +
- yanwyb/npu:v1+
 ``` ```
  
 ==== Get Model Conversion Tools ==== ==== Get Model Conversion Tools ====
  
-Get source [[gl>khadas/vim4_npu_sdk]].+Get source [[gh>khadas/vim4_npu_sdk]].
  
 ```shell ```shell
-$ git clone https://gitlab.com/khadas/vim4_npu_sdk+$ git lfs install 
 +$ git lfs clone https://github.com/khadas/vim4_npu_sdk 
 +$ cd vim4_npu_sdk 
 +$ ls 
 +adla-toolkit-binary  adla-toolkit-binary-3.1.7.4  convert-in-docker.sh  Dockerfile  docs  README.md
 ``` ```
 +
 +  * ''adla-toolkit-binary/docs'' - SDK documentations
 +  * ''adla-toolkit-binary/bin'' - SDK tools required for model conversion
 +  * ''adla-toolkit-binary/demo'' - Conversion examples
 +
 +<WRAP important>
 +If your kernel is older than 241129, please use branch npu-ddk-1.7.5.5.
 +</WRAP>
  
 ==== Convert ==== ==== Convert ====
Line 42: Line 52:
 After training model, modify ''ultralytics/ultralytics/nn/modules/head.py'' as follows. After training model, modify ''ultralytics/ultralytics/nn/modules/head.py'' as follows.
  
-```diff ultralytics/nn/modules/head.py.patch+```diff head.py
 diff --git a/ultralytics/nn/modules/head.py b/ultralytics/nn/modules/head.py diff --git a/ultralytics/nn/modules/head.py b/ultralytics/nn/modules/head.py
 index 0b02eb3..0a6e43a 100644 index 0b02eb3..0a6e43a 100644
Line 66: Line 76:
 +            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, dfl], 1).permute(0, 2, 3, 1).unsqueeze(1)) ++            results.append(torch.cat([cls, dfl], 1))
-+            # results.append(torch.cat([cls, dfl], 1))+
 +        return tuple(results) +        return tuple(results)
 + +
 ``` ```
 +
 +<WRAP important>
 +If you pip-installed ultralytics package, you should modify in package.
 +</WRAP>
  
 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 96:
 $ python export.py $ python export.py
 ``` ```
 +
 +<WRAP important>
 +Use [[https://netron.app/ | Netron]] to check your model output like this. If not, please check your ''head.py''.
 +
 +{{:products:sbc:vim4:npu:demos:yolov8n-vim4-output-ddk-3-4-7-7.webp?600|}}
 +</WRAP>
  
 Enter ''vim4_npu_sdk/demo'' and modify ''convert_adla.sh'' as follows. Enter ''vim4_npu_sdk/demo'' and modify ''convert_adla.sh'' as follows.
Line 105: Line 124:
         --quantize-dtype int16 --outdir onnx_output  \         --quantize-dtype int16 --outdir onnx_output  \
         --channel-mean-value "0,0,0,255"  \         --channel-mean-value "0,0,0,255"  \
 +        --inference-input-type "float32" \
 +        --inference-output-type "float32" \
         --source-file dataset.txt  \         --source-file dataset.txt  \
         --batch-size 1 --target-platform PRODUCT_PID0XA003         --batch-size 1 --target-platform PRODUCT_PID0XA003
Line 124: Line 145:
 $ git clone https://github.com/khadas/vim4_npu_applications $ git clone https://github.com/khadas/vim4_npu_applications
 ``` ```
 +
 +<WRAP important>
 +If your kernel is older than 241129, please use version before tag ddk-3.4.7.7.
 +</WRAP>
  
 ==== Install dependencies ==== ==== Install dependencies ====
Line 147: Line 172:
  
 # Run # Run
-sudo ./yolov8n -m ../data/yolov8n_int8.adla -p ../data/horses.jpg+$ ./yolov8n -m ../data/yolov8n_int8.adla -p ../data/horses.jpg
 ``` ```
 +
 +{{:products:sbc:vim4:npu:demos:yolov8n-demo-output.webp?800|}}
  
 === Camera input demo === === Camera input demo ===
Line 163: Line 190:
  
 # Run # Run
-sudo ./yolov8n_cap -m ../data/yolov8n_int8.adla -d 0 -w 1920 -h 1080+$ ./yolov8n_cap -m ../data/yolov8n_int8.adla -d 0
 ``` ```
  
Last modified: 2023/09/18 01:52 by sravan