ViM4 NPU PYTHON script

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

Ubuntu

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

Yes official 22.04

Please describe your issue below:

Translate NPU example command line in Python script

Post a console log of your issue below:

Dear friends, do you know a way to convert this cli like this :

$ sudo ./yolov8n_cap -m ../data/yolov8n_int8.adla -d 0 -w 320 -h 240

In python script : I tested this

from ultralytics import YOLO
import cv2

cap = cv2.VideoCapture(0)
model = YOLO ('yolov8n_int81.adla',task='detect')

while True:
    ret, img= cap.read()
    results = model(img, stream=True)
    cv2.imshow('Webcam', img)
    if cv2.waitKey(1) == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
It seems working but I meet this error message : 
fp16 &= pt or jit or onnx or xml or engine or nn_module or triton  # FP16
TypeError: unsupported operand type(s) for &=: 'bool' and 'str'

Note : Python 3.9.16 used.
Except this NPU works fine through cli.

Kind regards,

Hello @strapp

The YOLO library doesn’t support to run NPU on the VIM4.
At the moment you need to use the library and examples provided in: vim4_npu_applications/yolov8n_cap at master · khadas/vim4_npu_applications · GitHub

Regards.

Hi Electr1,

Thx for your support.

For my information this doesn’t work with VIM4 (?) : net.setPreferableTarget(cv2.dnn.DNN_TARGET_NPU)
I assume to use yolov8n.onnx.

Kind regards,

@strapp at the moment the only working backend for NPU is from the aml_npu examples.

Regards.