Pytorch Yolov8 Model conversion guide

Which Khadas SBC do you use?

VIM3 Pro

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu 20.04

Which version of system do you use? Khadas official images, self built images, or others?

Khadas Official Image with kernal 5.15

Please describe your issue below:

I am attempting to convert a yolov8 segmentation model so I can run it on the NPU. I have another host VM running docker and the NPU SDK. I have my model placed in the /bin folder of the SDK and I am in the stuck on modifying the conversion scripts before I run the ./ executable. can anyone walk me through what to precisely modify??

Post a console log of your issue below:

Hello @lcollante

@Louis-Cheng-Liu will help you then.

Hello @lcollante ,

You should modify, and in aml_npu_sdk/acuity-toolkit/demo

The red boxes are the codes you may need to modify.

First red box is your model name. Second is import your original model. Choose your model platform example from at last COMMENT. Third is the normalization of your model.

Second is quantitation type. We suggest choose int8.

If you use VIM3, second box should be VIPNANOQI_PID0X88. VIM3L is VIPNANOQI_PID0X99.

After modifying, run

About more details, you can refer aml_npu_sdk/docs/en/Model Transcoding and Running User Guide (1.0).pdf title 2 Tools.

okay so I have modified those scripts but I get this error when I run

keep in mind my entire sdk is installed in /NPU_Workspace/aml_npu_sdk in the root directory.

I have tried to nano into the file and changed any of the directories as it seemed as if those changes need to be made but I have had no luck so far. What am I missing?
Thank you!

Hello @lcollante ,

Have it the path? It only the mistake for no the path. Have you done other changes except modifying that three scripts?

@Louis-Cheng-Liu at first I did not modify any other scripts.
When I saw the “no such file or directory” error, I went into the file and tried to change the directory settings to match where the SDK is located and I still recieved the same errors.


I brought everything to a personal VM of mine and rebuilt the entire conversion platform with both the NPU SDK AND the KSNN repository. just for some context: this model of mine one that I’ve built from scratch BEFORE I purchased the VIM3 board. so I’ve simply grabbed the .pt file from my personal machine and brought it into the NPU SDK. Additionally, I had a .onnx version of that same model that I converted myself and I brought that individually into the NPU SDK as well. There are no other folders or files associated. now that I have rebuilt the SDKs on another VM, I am receiving these errors for both C++ API and the Python API methods, respectfully:

C++ API (done with the convert-in-docker method)

Python API (done with the KSNN method)

I do not understand what I am looking at. HELP!

Hello @lcollante ,

It maybe the link broken. Do your use git clone download the aml_npu_sdk? Use other method may cause link broken.

Second problem is the version of onnx opset. You can refer this topic.
Unable to convert yolov8n to .nb - VIM3 - Khadas Community

Is the problem still alive? It is the syntax error. Please check your command whether right or not.

@Louis-Cheng-Liu I converted the opset version of my onnx model now but every time I try again and again to run the conversion process I still keep receiving that syntax error or the following error:

Additionally, I have checked dozens of times now, there is no where in my code that a ‘(’ syntax could be occuring

Hello @lcollante ,

Sorry, i forget that converting model must be done on Linux PC.

The last reply with the image I had posted was an attempt to convert using the Python API on the VIM3 itself, but all of my previous errors were on Ubuntu 22.04 VMs on another host machine. Nearly all of my conversion attempts have been on a separate host. I have not moved forward with any progress yet. thank you

Hello @lcollante ,

Is error your meet?

The convert tool update last week. The new tool need to use git lfs clone to get the codes.

$ git lfs install
$ git lfs clone --recursive

The new code i run has nothing wrong.

@Louis-Cheng-Liu could I ask you to elaborate on the command for the conversion?

I have been following the conversion command via the documentation from the KSNN github. I am not understanding the set.txt in your command to convert and I do not understand why the documentation requires an input of a dataset (./data/dataset/dataset0.txt) that is not related to the yoloV8 model.

I am currently reworking the solution you have provided and I will message back as soon as I have a result

Hello @lcollante ,

About convert command, you can refer this. KSNN API [Khadas Docs]

In general, the model need to be quantified when convert model. Quantitation means use int8 or int16 weight instead of float32 weight. This process need some images to make loss lower. The images have better about actual usage scenario. The images in dataset.txt is used to model quantitation. We suggest the number of quantitative images is about 200-500. what is more, batch-size is the number of quantitation image each step and iterations is the number of quantitation step. batch-size × iterations is the number of images you use.