Open RizwanMunawar opened 1 week ago
π Hello @RizwanMunawar, thank you for submitting an ultralytics/ultralytics
π PR! Your contribution to enhancing visualization in classification plots is greatly appreciated. π¨ To ensure a smooth process, please review the following checklist:
ultralytics/ultralytics
main
branch. If it's behind, please update it by clicking the 'Update branch' button or by running git pull
and git merge main
locally.π For further guidance, please refer to our Contributing Guide. If you encounter any issues or have additional questions, feel free to comment here, and we'll assist you.
π Your proposed updates to text rendering and plotting aesthetics look promising. Dynamic text coloring and background rectangles will undoubtedly improve the visualization and user experience. Thank you for including a well-documented diff and comparative media to showcase your work. ποΈβ¨
This is an automated response to help streamline the process, but rest assured that an Ultralytics engineer will review your PR in detail and provide further guidance soon. π Thank you for contributing to Ultralytics!
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 72.75%. Comparing base (
c1860b8
) to head (ef20fa1
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Your pull request is modifying functions with the following pre-existing issues:
π File: ultralytics/engine/results.py
Function | Unhandled Issue |
---|---|
plot |
error: OpenCV(4.10.0) :-1: error: (-5:Bad argument) in function 'polylines' ultralytics.... Event Count: 1 |
plot |
TypeError: Argument 'thickness' is required to be an integer ultralytics.utils.plotting ... Event Count: 1 |
Did you find this useful? React with a π or π
@RizwanMunawar yeah nice idea! Personally I do have issues of current style of classify plotting when the background is white(basically can not see the plotted names).
I think you could start this PR with the box_style
argument we already have for Annotator.text method:
https://github.com/ultralytics/ultralytics/blob/c5ac5548aeac8ed1554ef6224bd3d839974abc5b/ultralytics/utils/plotting.py#L494-L494
which I created this style(similar with the one you proposed in this PR) for visualizations when training/validating classification task.
A val_batch0_pred.jpg
example below:
Ideally if we want this style we could implement this by directly adding
box_style=True
here: https://github.com/ultralytics/ultralytics/blob/c5ac5548aeac8ed1554ef6224bd3d839974abc5b/ultralytics/engine/results.py#L565-L565
and pass different color based on the predicted categories, instead of (255, 255, 255)
.
@Laughing-q Wow, I didn't realize the same code had been used for plotting during the training. Your idea looks good, Let me test it.
Edit: BTW, I just performed testing and I have noticed the changes we made are not used in training and validation, these are only related to predictions i.e yolo classify predict
. Additionally If I set box_style=True, annotator.text([x, x], text, txt_color=(255, 255, 255), box_style=True)
. I am getting the mentioned output.
I think the main issue here is, that text includes not a single class, it's a combination of 5 classes, which I believe can not be plotted directly so loop will be required.
@RizwanMunawar I've updated the code a bit to reuse the box_style
argument, currently we just add box_style=True
in Results.plot()
for classification then it's all good.
@Laughing-q ok, I will test it sometime today. In the meantime can you please attach some output results with new changes you made?
@RizwanMunawar here it is!
with box_style=True
:
box_style=False
:
Also the training/validation plots become using the same red color, but I think it's ok since the category context is still different.
@Laughing-q ok, Thanks. so this PR is ready?
good to go from my side
@Laughing-q ok thanks, @glenn-jocher Hi, can you please take a look, If everything is good, maybe we can merge this PR. Thanks
@glenn-jocher Hi, this PR enhances the visualization of classification results. Currently, there are no background rectangles or distinct text colours for each classified object. This PR introduces these features. Thanks
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Enhanced visualizations by improving multi-line text rendering with color-coded backgrounds for better readability. πΌοΈβ¨
π Key Changes
annotator.text
function to remove hardcoded font color settings, offering more flexibility.π― Purpose & Impact