-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
PR curve of the model trained with 35 classes #13106
Comments
Hello, Thank you for reaching out and for your detailed question! The PR curve visualization in YOLOv5 is indeed optimized for datasets with fewer classes, which is why you see the per-class legend for datasets with up to 20 classes. For datasets with more classes, the legend can become cluttered and less readable. To address your specific need for displaying the per-class legend with 35 classes, you can modify the plotting script to accommodate more classes. Here's a step-by-step guide to help you achieve this:
def plot_pr_curve(px, py, ap, save_dir='pr_curve.png', names=()):
# Plot PR curve
fig, ax = plt.subplots(1, 1, figsize=(9, 6), tight_layout=True)
ax.plot(px, py, linewidth=1, color='grey')
ax.set_xlabel('Recall')
ax.set_ylabel('Precision')
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.grid(True)
ax.set_title(f'Precision-Recall curve: mAP @kim2429.5 = {ap:.3f}')
# Add per-class legend
for i, name in enumerate(names):
ax.plot(px[:, i], py[:, i], linewidth=1, label=f'{name} ({ap[i]:.3f})')
ax.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
fig.savefig(save_dir, dpi=200)
plt.close(fig)
This should allow you to visualize the PR curve with all 35 classes included in the legend. If you encounter any issues or need further assistance, please provide a minimum reproducible example of your code and ensure you are using the latest versions of I hope this helps! If you have any further questions, feel free to ask. 😊 |
Thank you for getting back to me. I adjusted the code in utils/metrics.py following your suggestion. Unfortunately, I found the plot_pr_curve function in utils/metrics.py, not plots.py. However, the val.py code did not work. This is the error message. Please confirm this. Traceback (most recent call last): |
Search before asking
Question
Hello,
I used the YOLOv5s model for training the dataset consisting of 35 classes.
The PR curve displays the per-class legend if classes are less than 21.
How can I get a PR curve displaying the per-class legend in my case?
Additional
No response
The text was updated successfully, but these errors were encountered: