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

Adjust legend labels for classes without instances #5174

Merged
merged 4 commits into from
Oct 14, 2021

Conversation

NauchtanRobotics
Copy link
Contributor

@NauchtanRobotics NauchtanRobotics commented Oct 14, 2021

See issue #5158

Before

PR Curve legend has labels for "D00" and "D10" but should have labels for "D40" and "EB".
D00 and D10 have no bounding box instances, and no predictions.
'stats' omits classes that have len = 0; therefore 'names' should also omit empty classes.

labels
PR_curve
:

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved class naming handling in precision-recall and F1 score calculations and plots.

📊 Key Changes

  • Added filtering to only include class names that correspond to classes with data when generating metrics.
  • Converted the filtered class names list to a dictionary with an enumerated index for consistent referencing.

🎯 Purpose & Impact

  • Ensures that metric plots only display relevant classes, reducing clutter and potential confusion.
  • Impacts users by providing clearer and more accurate visualization of model performance metrics, aiding in better model evaluation and interpretation. 📈🔍

@NauchtanRobotics
Copy link
Contributor Author

After

The legend of PR curve has labels "D40" and "EB" which is correct (same as labels.jp
PR_curve
g)

@NauchtanRobotics
Copy link
Contributor Author

@glenn-jocher For future reference, how do you feel about incrementally introducing typing? Would make understanding the code more rapid and development easier. E.g.

from typing import List, Dict


def plot_pr_curve(
    px: np.ndarray, 
    py: np.ndarray, 
    ap: List[float], 
    save_dir: str='pr_curve.png', 
    names: Dict={}
):

@glenn-jocher
Copy link
Member

@NauchtanRobotics thanks for the PR! Would this simplified version also work?

    names = [v for k, v in names.items() if k in unique_classes]  # list of unique names
    names = {i: v for i, v in enumerate(names)}  # to dict

Yes, typing is one of the options we are considering for improving the codebase, but for consistency we'd probably want to apply formatting updates across the whole repo, so let's leave it off the plate for now. Thanks!

@glenn-jocher glenn-jocher linked an issue Oct 14, 2021 that may be closed by this pull request
@NauchtanRobotics
Copy link
Contributor Author

Yes, that works a treat @glenn-jocher. See all 4 affected charts.

Feel free to squash down to one commit
P_curve
.
PR_curve
R_curve

F1_curve
.

@glenn-jocher glenn-jocher changed the title legend-labels Adjust legend labels for classes without instances. Adjust legend labels for classes without instances Oct 14, 2021
@glenn-jocher glenn-jocher merged commit 0be58f1 into ultralytics:master Oct 14, 2021
@glenn-jocher
Copy link
Member

@NauchtanRobotics PR is (squashed and) merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐

BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* legend-labels Adjust legend labels for classes without instances.

* ultralytics#5158 Re-indexed series names: only classes containing data.

* ultralytics#5158 Re-indexed series names: only classes containing data.

* Cleanup

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
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.

Classes with no instances causes legend misalignment
2 participants