Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yolov8Post-processing #5495

Closed
zjkhahah opened this issue Jun 9, 2024 · 3 comments
Closed

yolov8Post-processing #5495

zjkhahah opened this issue Jun 9, 2024 · 3 comments

Comments

@zjkhahah
Copy link

zjkhahah commented Jun 9, 2024

I printed the loaded model, but it seems that many confidence levels corresponding to categories are 1. Is this normal? Or something went wrong?
The model uses official yolov8s

##############################
ncnn::Extractor ex = yolo.create_extractor();
ex.input("in0", in_pad);
ncnn::Mat out;
ncnn::Mat transpose_out;
ex.extract("out0", out);
transpose(out, transpose_out);

for (int i = 0; i < transpose_out.h; i++) {
for (int j = 0; j < transpose_out.w; j++) {
printf("%f,", transpose_out[i *(4+ num_class) +j]);
}
printf("\n");
}
printf("width=%d,height=%d,channels=%d\n", transpose_out.w, transpose_out.h, transpose_out.c);
return 0;
}
############################
This is the output

1717913260509
464.000000,736.000000,512.000000,736.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.500000,0.500000,1.000000,0.500000,0.500000,0.500000,0.500000,1.000000,0.500000,1.000000,0.500000,0.500000,0.500000,0.500000,0.500000,0.500000,0.000000,0.500000,1.000000,0.500000,0.500000,0.500000,0.500000,0.500000,0.000000,0.000000,0.000000,0.000000,1.000000,0.500000,0.000000,0.500000,1.000000,0.500000,0.000000,1.000000,
496.000000,688.000000,512.000000,832.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.000000,1.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.500000,0.000000,0.000000,0.000000,0.000000,0.500000,0.500000,1.000000,0.500000,0.500000,0.500000,0.500000,0.500000,0.500000,0.500000,1.000000,0.000000,0.500000,0.000000,1.000000,0.500000,0.500000,0.500000,0.500000,1.000000,0.000000,0.000000,1.000000,0.000000,1.000000,0.000000,0.500000,1.000000,0.500000,0.000000,0.000000,
width=84,height=8400,channels=1

@whyb
Copy link
Contributor

whyb commented Jun 12, 2024

I just submitted a pull request for yolov8 example #5506
I hope it can be helpful to you.

@zjkhahah
Copy link
Author

Thanks for the reply. I seem to have a problem running the code.
fbe2c79f74a48a0d08244e51cf9aff0

I tried to print the highest confidence level for the value of out, but the output did not seem to be correct. These confidence levels felt too high.Below is the result and code I printed

ncnn::Mat out;
ex.extract("out0", out);
cv::Mat a(out.h, out.w, CV_32FC1);
memcpy((uchar*)a.data, out.data, out.w * out.h * sizeof(float));
for (int col = 0; col < a.cols; ++col) {
float maxVal = std::numeric_limits::lowest(); // 初始化为可能的最小浮点数
for (int row = 4; row < 84; ++row) { // 从第 4 行到第 83 行(索引从 0 开始)
float value = a.at(row, col);
if (value > maxVal) {
maxVal = value; // 更新最大值
}
}
std::cout << "Column " << col << " max value from row 4 to 84 is: " << maxVal << std::endl;
}

aed0ff9ba1dc19a003a991696c95244

@whyb
Copy link
Contributor

whyb commented Jun 14, 2024

Thanks for the reply. I seem to have a problem running the code. fbe2c79f74a48a0d08244e51cf9aff0

I tried to print the highest confidence level for the value of out, but the output did not seem to be correct. These confidence levels felt too high.Below is the result and code I printed

ncnn::Mat out; ex.extract("out0", out); cv::Mat a(out.h, out.w, CV_32FC1); memcpy((uchar*)a.data, out.data, out.w * out.h * sizeof(float)); for (int col = 0; col < a.cols; ++col) { float maxVal = std::numeric_limits::lowest(); // 初始化为可能的最小浮点数 for (int row = 4; row < 84; ++row) { // 从第 4 行到第 83 行(索引从 0 开始) float value = a.at(row, col); if (value > maxVal) { maxVal = value; // 更新最大值 } } std::cout << "Column " << col << " max value from row 4 to 84 is: " << maxVal << std::endl; }
aed0ff9ba1dc19a003a991696c95244

我知道这个问题,这个原因不是因为我这边的原因,而是您导出的yolov8.ncnn.* 模型是仅固定支持[1,3,640,640]的模型,并不支持动态shape输入造成的。

这个错误的模型会导致输入进去的数据为了保持图像原比例缩放,并不符合模型要求的[1,3,640,640],实际上有可能是[1,3,640,540],所以模型内部会错位读取图像,对结果造成严重偏差。

只是要尝试效果的话,您可以直接把输入的图片用画图工具或者cv::resize() 修改成640x640的尺寸。

pnnx本身是支持动态shape输入的,您可以去参考 https://github.com/pnnx/pnnx?tab=readme-ov-file#------detailed-options

导出正确的支持动态shape输入的模型,期待您的好消息~🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants