You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched the YOLOv5 issues and discussions and found no similar questions.
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)
PYBIND11_MODULE(onnx_loader, 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
image = cv2.imread(image_path, cv2.IMREAD_COLOR) # Load image in color mode
if image is None:
raise ValueError(f"Could not open or find the image: {image_path}")
# Convert from BGR to RGB format
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Resize the image to match the input size expected by the model
image = cv2.resize(image, input_size)
# Normalize the image to [0, 1] range
image = image.astype(np.float32) / 255.0 # Convert to float and normalize
# Rearrange the image to CHW format (1, C, H, W)
image_data = np.transpose(image, (2, 0, 1)) # Convert to CHW format
image_data = np.expand_dims(image_data, axis=0) # Add batch dimension
print(f"Image preprocessed: type = {type(image_data)}, shape = {image_data.shape}")
return image_data, image # Return the preprocessed image data
The text was updated successfully, but these errors were encountered:
👋 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.
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.
A green badge means all YOLOv5 GitHub Actions Continuous Integration (CI) tests are passing. These tests verify correct operation on macOS, Windows, and Ubuntu.
Introducing YOLOv8 🚀
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! 😊
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 <onnxruntime_cxx_api.h>
#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(onnx_loader, 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
image = cv2.imread(image_path, cv2.IMREAD_COLOR) # Load image in color mode
if image is None:
raise ValueError(f"Could not open or find the image: {image_path}")
# Convert from BGR to RGB format
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Resize the image to match the input size expected by the model
image = cv2.resize(image, input_size)
# Normalize the image to [0, 1] range
image = image.astype(np.float32) / 255.0 # Convert to float and normalize
# Rearrange the image to CHW format (1, C, H, W)
image_data = np.transpose(image, (2, 0, 1)) # Convert to CHW format
image_data = np.expand_dims(image_data, axis=0) # Add batch dimension
print(f"Image preprocessed: type = {type(image_data)}, shape = {image_data.shape}")
return image_data, image # Return the preprocessed image data
The text was updated successfully, but these errors were encountered: