【黄埔学院】 paddle训练的yolov4,成功转成onnx模型,但用onnxruntime运行时报错
Created by: Tinagao222
**问题:**Yolov3可以转onnx并允许成功,但yolov4转成功后,运行失败了。 报错信息如下: Exception has occurred: Fail [ONNXRuntimeError] : 1 : FAIL : Non-zero status code returned while running TopK node. Name:'' Status Message: value of k must not be negative
python程序如下: import numpy import onnxruntime as rt import cv2 import numpy as np
def drawbbox(img, results, score_thr=0): color = [(255,0,0),(0,255,0)] a = len(results[0]) for i in range(len(results[0])): scores = results[0][i][1] c = int(results[0][i][0]) x1 = int(results[0][i][2]) y1 = int(results[0][i][3]) x2 = int(results[0][i][4]) y2 = int(results[0][i][5]) if scores >score_thr: cv2.rectangle(img, (x1,y1),(x2,y2),color[c],2)
mean = 123.675 #np.array([123.675, 116.28, 103.53]) std = 58.395 #np.array([58.395, 57.12, 57.375])
sess = rt.InferenceSession("./work_dirs/yolov4_1.onnx") input_size = sess.get_inputs()[0].name input_name = sess.get_inputs()[1].name
img_size = np.array([[1944,2592]]) #(高,宽)
image = cv2.imread("./test/2.jpg") img = cv2.resize(image, (608,608)) img_data = np.array(img) #0:高,1:宽,2:通道数 img_data = np.true_divide((img_data - mean),std) img_data = img_data.transpose((2,0,1)) img_data = np.expand_dims(img_data, axis=0) #img_data = np.expand_dims(img_data, axis=0) img_data = img_data.astype(np.float32) pred_onx = sess.run(None, {input_size:img_size,input_name:img_data})[0] drawbbox(image, pred_onx, 0.5) cv2.imwrite('2.jpg', image)