Geekgineer / YOLOs-CPP

A high-performance C++ headers for real-time object detection using YOLO models, leveraging ONNX Runtime and OpenCV for seamless integration. Supports multiple YOLO versions (v5, v7, v8, v10, v11) with optimized inference on CPU and GPU. Includes sample code, scripts for image, video, and live camera inference, and tools for quantization.
310 stars 28 forks source link

Only the yolo10n_uint8.onnx model works for inference. #3

Closed Matthew-CQ closed 1 week ago

Matthew-CQ commented 2 weeks ago

Hi, Geekgineer,

Thank you for your great work! I encountered an error when using the model (though it works only with yolo10n_uint8.onnx model). Is there something wrong with the decoder part or onnx model? I would appreciate your response at your earliest convenience.

yolo11n.onnx yolo11n.onnx

Other models Other models

Best Regards, Matthew

Geekgineer commented 2 weeks ago

Hello Matthew-CQ, you are welcome please ensure you use the correct model with the corresponding header.


// Include necessary headers
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

#include "YOLO11.hpp" // Ensure YOLO11.hpp or other version is in your include path

int main()
{
    // Configuration parameters
    const std::string labelsPath = "../models/coco.names";       // Path to class labels
    const std::string modelPath  = "../models/yolo11n.onnx";     // Path to YOLO11 model
    const std::string imagePath  = "../data/dogs.jpg";           // Path to input image
    bool isGPU = true;                                           // Set to false for CPU processing

    // Initialize the YOLO11 detector
    YOLO11Detector detector(modelPath, labelsPath, isGPU);

    // Load an image
    cv::Mat image = cv::imread(imagePath);

    // Perform object detection to get bboxs
    std::vector<Detection> detections = detector.detect(image);

    // Draw bounding boxes on the image
    detector.drawBoundingBoxMask(image, detections);

    // Display the annotated image
    cv::imshow("YOLO11 Detections", image);
    cv::waitKey(0); // Wait indefinitely until a key is pressed

    return 0;
}
Matthew-CQ commented 2 weeks ago

Hi Geekgineer,

I am sure that I am using the correct model along with the corresponding header. However, the result is the same as with your code after building.

image

Geekgineer commented 2 weeks ago

Hi Matthew,

Please make sure you have built the project according to the README.md also the libs like OpenCV match the current versions etc. for the below image it worked for me.

dogs_o

image

a333klm commented 1 week ago

I have also this problem. I made sure to have opencv 4.5.5 with this adaptation in the CmakeLists.txt

cmake_minimum_required(VERSION 3.0.0)
project(yolo_ort)

option(ONNXRUNTIME_DIR "Path to built ONNX Runtime directory." STRING)
message(STATUS "ONNXRUNTIME_DIR: ${ONNXRUNTIME_DIR}")

set(OpenCV_DIR "/home/username/repos/opencv-4.5.5/build")
find_package(OpenCV 4.5.5 REQUIRED)
...

But the output is identical to @Matthew-CQ In image_interference.cpp I added this line of code to verify the OpenCV version:

    std::cout << "OpenCV Version: " << CV_VERSION << std::endl;

It confirms, that 4.5.5 is used.

Also yolov10 works, but yolov11 does not.

Matthew-CQ commented 1 week ago

HI, @a333klm

My OpenCV version is 4.5.4. After building OpenCV 4.10.0 and using it, I got the same incorrect results. It's weird. Maybe the ONNX model is incorrect?

Geekgineer commented 1 week ago

Hello guys,

in case you confront issues with the models provided in the project you can get your fresh onnx yolov11 models by exporting the original models or your custom ones using this colab env:

https://colab.research.google.com/github/ultralytics/ultralytics/

regards,

Matthew-CQ commented 1 week ago

Hi @Geekgineer @a333klm,

I fixed it by using notebook from @Geekgineer to generate a new ONNX model (yolo11n.onnx). After replacing it, I got the correct output.

The steps are shown below:

  1. Run Setup → Predict → Export (change format to ONNX)

  2. Download the yolo11n.onnx model and replace the old one.

Regards,