Skip to content

Fix normalization parameters in YOLO example to support multi-channel mean and scale factors#26614

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
KangJialiang:fix-multi-channel-mean-scale-sample-dnn-yolo
Dec 16, 2024
Merged

Fix normalization parameters in YOLO example to support multi-channel mean and scale factors#26614
asmorkalov merged 1 commit intoopencv:4.xfrom
KangJialiang:fix-multi-channel-mean-scale-sample-dnn-yolo

Conversation

@KangJialiang
Copy link
Copy Markdown
Contributor

This branch and commit address an issue in the YOLO example (samples/dnn/yolo_detector.cpp) where the mean and scale parameters only affected the first channel (Blue) due to single-value input. The modification updates these parameters to accept multi-channel values, ensuring consistent preprocessing across all image channels.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

… mean and scale factors

This branch and commit address an issue in the YOLO example (samples/dnn/yolo_detector.cpp) where the mean and scale parameters only affected the first channel (B) due to single-value input. The modification updates these parameters to accept multi-channel values, ensuring consistent preprocessing across all image channels.
Copy link
Copy Markdown
Contributor

@gursimarsingh gursimarsingh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue has been fixed in 5.x where this sample has been merged with object_detection.cpp link

A better way to do this is #26326 for scale

@KangJialiang
Copy link
Copy Markdown
Contributor Author

The issue has been fixed in 5.x where this sample has been merged with object_detection.cpp link

A better way to do this is #26326 for scale

Thank you for the quick response and the helpful insights! As a newbee here, I really appreciate your guidance and welcome any corrections.

I understand that 4.x remains a primary version in use, and while the issue is resolved in 5.x, I believe it’s important to address it in 4.x as well.

Regarding #26315, I partially disagree with the claim that applying different scales to each channel is rare. At least in ImageNet classification, it’s standard practice to normalize each channel using its respective mean and std.

That said, I agree that ensuring consistency between the sample code and cv::dnn::Net::setInput is crucial. However, the current handling of mean and scale in the example seems inconsistent—mean is applied channel-wise, while scale channel-invariant. This could lead to confusion, as users might intuitively expect both to apply per channel. Without proper clarification, this behavior might not be the most user-friendly practice.

@asmorkalov asmorkalov self-assigned this Dec 16, 2024
@asmorkalov asmorkalov added this to the 4.11.0 milestone Dec 16, 2024
@asmorkalov asmorkalov merged commit 03f90aa into opencv:4.x Dec 16, 2024
@KangJialiang KangJialiang deleted the fix-multi-channel-mean-scale-sample-dnn-yolo branch December 16, 2024 12:40
@asmorkalov asmorkalov mentioned this pull request Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants