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

Modify class names in YOLOv8 #570

Closed
1 task done
davidemerolla opened this issue Feb 12, 2024 · 4 comments
Closed
1 task done

Modify class names in YOLOv8 #570

davidemerolla opened this issue Feb 12, 2024 · 4 comments
Labels
question A HUB question that does not involve a bug Stale

Comments

@davidemerolla
Copy link

Search before asking

Question

Hello! I've just trained a YOLOv8n model and got a best.pt file. Everything is performing well, but i have an issue. I'm doing inference on a video and i want to change some class names without retraining the entire model. Is it possible to modify directly the 'best.pt' file so that i can use it also for other videos?

P.S.
I would like also to use the best.pt file in ultralytics hub app if it possible, but don't know how to do it! First i need to change some class names
Thanks

Additional

No response

@davidemerolla davidemerolla added the question A HUB question that does not involve a bug label Feb 12, 2024
@UltralyticsAssistant
Copy link
Member

@davidemerolla hello!

Great to hear that your YOLOv8n model is performing well! To change the class names for inference without retraining, you can simply modify the names list in the *.yaml file that corresponds to your model's classes. This file is used during inference to map class IDs to class names. Just update the names there, and your best.pt model will output the new class names during inference.

Regarding using your best.pt file with the Ultralytics HUB app, you can upload your model and the modified *.yaml file directly to the app. The HUB Docs provide detailed instructions on how to do this.

If you have any further questions or need more assistance, feel free to ask. Happy inferencing! 😊

Copy link

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Mar 14, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2024
@BitCode-in
Copy link

BitCode-in commented Apr 4, 2024

Hello! You can rename a class in this way.

import torch
from ultralytics import YOLO

model = torch.load("best.pt", map_location="cpu")

model["model"].names[0] = "New name"

torch.save(model, "save_best.pt")

model = YOLO(r"save_best.pt")
print(model.names)

https://github.com/BitCode-in/rename_torch_or_yolov_names/tree/main

@UltralyticsAssistant
Copy link
Member

@BitCode-in hello! While the code snippet you shared outlines a method to rename class names in a PyTorch model file, it's important to note that directly manipulating .pt files should be done with caution and understanding of the model structure. Also, we typically recommend making name changes in the *.yaml file for simplicity and to avoid potential issues with model integrity.

However, your approach provides an alternative for those comfortable with PyTorch and direct model manipulation. Just be sure to verify the model's performance and output accuracy after such changes.

Happy to see community members sharing their solutions! If there's anything specific you're trying to achieve or any further questions, feel free to ask. 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A HUB question that does not involve a bug Stale
Projects
None yet
Development

No branches or pull requests

3 participants