From dc15242cbdc56887a68e78c864119f6918bca0de Mon Sep 17 00:00:00 2001 From: memorylorry Date: Sun, 25 Aug 2024 07:05:52 +0800 Subject: [PATCH] Fix YOLOv8 C++ ONNXRuntime transpose op (#15779) Co-authored-by: Glenn Jocher --- examples/YOLOv8-ONNXRuntime-CPP/inference.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp b/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp index 5154a8303ad..2ee993eed79 100644 --- a/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp +++ b/examples/YOLOv8-ONNXRuntime-CPP/inference.cpp @@ -221,8 +221,8 @@ char* YOLO_V8::TensorProcess(clock_t& starttime_1, cv::Mat& iImg, N& blob, std:: case YOLO_DETECT_V8: case YOLO_DETECT_V8_HALF: { - int strideNum = outputNodeDims[1];//8400 - int signalResultNum = outputNodeDims[2];//84 + int signalResultNum = outputNodeDims[1];//84 + int strideNum = outputNodeDims[2];//8400 std::vector class_ids; std::vector confidences; std::vector boxes; @@ -230,18 +230,18 @@ char* YOLO_V8::TensorProcess(clock_t& starttime_1, cv::Mat& iImg, N& blob, std:: if (modelType == YOLO_DETECT_V8) { // FP32 - rawData = cv::Mat(strideNum, signalResultNum, CV_32F, output); + rawData = cv::Mat(signalResultNum, strideNum, CV_32F, output); } else { // FP16 - rawData = cv::Mat(strideNum, signalResultNum, CV_16F, output); + rawData = cv::Mat(signalResultNum, strideNum, CV_16F, output); rawData.convertTo(rawData, CV_32F); } //Note: //ultralytics add transpose operator to the output of yolov8 model.which make yolov8/v5/v7 has same shape //https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt - //rowData = rowData.t(); + rawData = rawData.t(); float* data = (float*)rawData.data;