Vim3部署yolov8n遇到图像大小问题resize input pictures error ! Set nn inputs error!

vim3 ubuntu20.04 offical
我正在尝试部署yolov8n,使用的是ksnn例程里面的example但是会有输入画面大小的报错:
root@Khadas:/home/khadas/Desktop/yolov8n/ultralytics/ksnn/examples/yolov8n# python3 yolov8n-cap.py --model ./models/VIM3/yolov8n.nb --library ./libs/libnn_yolov8n.so --device 0
|—+ KSNN Version: v1.3 ±–|
Start init neural network …
Done.
resize input pictures error !!!
Set nn inputs error !!!
使用的是usb摄像头并且正确挂载在vidio0
我尝试修改yolov8n-cap.py里面的分辨率为640x640或者1280x720但是都没有用

使用picture input demo也会报同样的错

我调整了yolov8n-cap.py的主代码为:` yolov3 = KSNN(‘VIM3’)
print(’ |—+ KSNN Version: {} ±–| '.format(yolov3.get_nn_version()))

print('Start init neural network ...')
yolov3.nn_init(library=library, model=model, level=level)
print('Done.')
cap = cv.VideoCapture(int(cap_num))
cap.set(3, 640)
cap.set(4, 640)
while True:
    ret, orig_img = cap.read()
    if not ret:
        print("Failed to grab frame")
        break

    img = cv.resize(orig_img, (640, 640)).astype(np.float32)
    img[:, :, 0] = img[:, :, 0] - mean[0]
    img[:, :, 1] = img[:, :, 1] - mean[1]
    img[:, :, 2] = img[:, :, 2] - mean[2]
    img = img / var[0]
    
    img = img.transpose(2, 0, 1)
    cv_img = [img]

    print(f"Input image shape: {img.shape}")

    start = time.time()
    data = yolov3.nn_inference(cv_img, platform='ONNX', reorder='2 1 0', output_tensor=3, output_format=output_format.OUT_FORMAT_FLOAT32)
    end = time.time()
    print('Inference time: ', end - start)

    input0_data = data[2]
    input1_data = data[1]
    input2_data = data[0]

    input0_data = input0_data.reshape(SPAN, LISTSIZE, GRID0, GRID0)
    input1_data = input1_data.reshape(SPAN, LISTSIZE, GRID1, GRID1)
    input2_data = input2_data.reshape(SPAN, LISTSIZE, GRID2, GRID2)
    
    input_data = [
        np.transpose(input0_data, (2, 3, 0, 1)),
        np.transpose(input1_data, (2, 3, 0, 1)),
        np.transpose(input2_data, (2, 3, 0, 1))
    ]

    boxes, scores, classes = yolov3_post_process(input_data)

    if boxes is not None:
        draw(orig_img, boxes, scores, classes)
    
    cv.imshow("capture", orig_img)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv.destroyAllWindows()`

运行后输出:root@Khadas:/home/khadas/Desktop/yolov8n/ultralytics/ksnn/examples/yolov8n# python3 testcamaer.py --model ./models/VIM3/yolov8n.nb --library ./libs/libnn_yolov8n.so --device 0 |---+ KSNN Version: v1.3 +---| Start init neural network ... Done. Input image shape: (3, 640, 640) resize input pictures error !!! Set nn inputs error !!!
貌似是这一行出现的报错:data = yolov3.nn_inference(cv_img, platform='ONNX', reorder='2 1 0', output_tensor=3, output_format=output_format.OUT_FORMAT_FLOAT32)

Hello @ZA_YU ,

你KSNN装错版本了,要装1.4版本。

好的 我去试试 谢谢你!---------------

错误解决了!但是出现了新的报错

raceback (most recent call last):
  File "yolov8n-cap.py", line 261, in <module>
    cv.imshow("capture", img)
cv2.error: OpenCV(4.9.0) /io/opencv/modules/core/src/array.cpp:2494: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

Hello @ZA_YU ,

这个好像是固件里面缺少OpenCV需要的QT库导致的错误。代码里面有直接保存图片的代码,你看一下有没有保存出结果图片。

1 Like

有输出结果 是用picture的demo输出的