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

Faster pre-processing for gray image input #9009

Merged
merged 3 commits into from
Aug 18, 2022

Conversation

cher-liang
Copy link
Contributor

@cher-liang cher-liang commented Aug 18, 2022

Using opencv cvtColor function is significantly faster than np.tile method to enforce 3 channel input

%%timeit -r 7 -n 100
im_cv_3ch=cv.cvtColor(im,cv.COLOR_GRAY2BGR)
13.2 ms ± 250 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

%%timeit -r 7 -n 100
im_np_3ch=np.tile(im[..., None], 3)
119 ms ± 2.62 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)

(Test done on Windows machine with Intel i5 CPU)

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved image preprocessing for grayscale images in YOLOv5.

📊 Key Changes

  • Modified the method to enforce 3-channel input for grayscale images.
  • Replaced np.tile() with OpenCV's cv2.cvtColor() for converting single-channel images to 3-channel BGR format.

🎯 Purpose & Impact

  • The change ensures better handling of grayscale images during preprocessing, leading to potentially improved model training and inference performance with such data.
  • Users working with grayscale datasets can expect their images to be correctly processed without manual intervention.
  • The use of OpenCV's function may result in more efficient and standardized conversion compared to NumPy's tiling method. 🚀

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

👋 Hello @cher-liang, thank you for submitting a YOLOv5 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with upstream/master. If your PR is behind upstream/master an automatic GitHub Actions merge may be attempted by writing /rebase in a new comment, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
# git checkout feature  # <--- replace 'feature' with local branch name
git merge upstream/master
git push -u origin -f
  • ✅ Verify all Continuous Integration (CI) checks are passing.
  • ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." -Bruce Lee

@glenn-jocher glenn-jocher merged commit c0e7a77 into ultralytics:master Aug 18, 2022
@glenn-jocher
Copy link
Member

@cher-liang 10x speedup, very nice!

PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐

ctjanuhowski pushed a commit to ctjanuhowski/yolov5 that referenced this pull request Sep 8, 2022
* faster 1 channel to 3 channels image conversion

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants