Open devendraswamy opened 1 month ago
👋 Hello @devendraswamy, thank you for reaching out with your issue regarding YOLOv5 🚀! This is an automated response to guide you further, and an Ultralytics engineer will be with you soon.
Please make sure you are following our Tutorials to ensure your setup is correct. They provide a helpful starting point for concepts including Custom Data Training and Hyperparameter Evolution.
If this is a 🐛 Bug Report, please provide a minimum reproducible example so we can better assist you.
In your case, ensure that both Python and C++ environments use the same preprocessing steps and ONNX model settings. Discrepancies could lead to different outputs.
Ensure you have Python>=3.8.0 with all requirements.txt installed and are using PyTorch>=1.8. To set up:
git clone https://github.com/ultralytics/yolov5 # clone
cd yolov5
pip install -r requirements.txt # install
YOLOv5 can be run in various environments. Consider using these resources with dependencies preinstalled, including CUDA/CUDNN, Python, and PyTorch:
Google Cloud Deep Learning VM: Check our GCP Quickstart Guide
Amazon Deep Learning AMI: See our AWS Quickstart Guide
Docker Image: Check our Docker Quickstart Guide
A green badge means all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests verify correct operation on macOS, Windows, and Ubuntu.
Check out YOLOv8, our latest model designed for superior performance in object detection, segmentation, and classification. Get started with:
pip install ultralytics
Feel free to provide more details as needed. We'll get back to you soon! 😊
@devendraswamy it seems like the discrepancy might be due to differences in preprocessing or input tensor handling between your Python and C++ implementations. Ensure that both environments use the same image preprocessing steps and input tensor shapes. Additionally, verify that the ONNX model and runtime versions are consistent across both implementations. If the issue persists, consider checking the ONNX model's input and output names and dimensions in both environments to ensure they match.
Search before asking
Question
I am facing the problem with YOLOV5 model. While I am testing my Python ONNX code, all the bounding box (bbox) values are correct. However, when I perform the same process with my C++ code, I am getting incorrect bbox values.
the image processed in ptyhon code: image_data = np.expand_dims(image_data, axis=0) # Add batch dimension
and feed that image to python pyd file (c++ inference file complied to pyd)
auto output_tensors = session.Run(Ort::RunOptions{ nullptr }, input_names, &input_tensor, 1, output_names, 1);
Additional
complied or build C++ code is:
include
include <pybind11/pybind11.h>
include <pybind11/numpy.h>
include
include
include
include
using namespace std; namespace py = pybind11;
class OnnxModel { public: OnnxModel(const std::string& model_path) : env(ORT_LOGGING_LEVEL_WARNING, "OnnxModel"), session(env, std::wstring(model_path.begin(), model_path.end()).c_str(), Ort::SessionOptions()) { Ort::AllocatorWithDefaultOptions allocator;
private: Ort::Env env; Ort::Session session; std::string input_name; std::string output_name; };
PYBIND11_MODULE(onnxloader, m) { py::class(m, "OnnxModel")
.def(py::init<const std::string&>())
.def("run", &OnnxModel::run);
}
Image feeding from python code:
Function to preprocess the image
def preprocess_image(image_path, input_size=(640, 640)):
Load the image using OpenCV