-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
How can I train one or several new classes on top of an existing training set. #3258
Comments
I think this tutorial should do it. All you need to do is to adapt the data/.yaml file for your specific dataset ! |
@yannclaes No, you don't understand what I'm saying! What I mean is ,simply,I want to train a new class on the base of the model that has been trained.At the same time, keep the classes that have been trained.I need to get 80+x classes. |
@SpongeBab by definition training a model modifies all of the weights and biases in it to minimize the loss on your new labels. There is no such thing as training a model on new classes while retaining existing weights and bias values anymore than I can drink a glass of water without affecting the water in the glass. |
@SpongeBab I think my answer still applies, but you have to provide COCO images too. When you modify your data.yaml, the number of classes is modified (as you noted, 80 + x) thus the number of outputs is modified too (it becomes nb_anchors * (80 + x + 5)). When loading your model with pre-trained weights, you'll fall into this: Line 91 in 7b36e38
Your Detect() module will be initialized with new weights corresponding to this new nc because shapes don't match anymore. So the bottom line is that to train a model on COCO + x classes, you need to provide data (images + labels) for all classes you want to train on, including COCO classes. Edit: found this after a quick search, conclusions were already identical. |
@glenn-jocher @yannclaes Thank you for your kind answers. |
@yannclaes Hi. |
That's exactly it ! I guess your goal is to save training time... However I think you have no other choice than full re-training from COCO weights, as explained in the tutorial. Nevertheless, preparing your data to include your 3 new classes should not be too hard as you would simply need to move your splits to the appropriate COCO split folders and do the same for your annotation files. I didn't know about GroupSoftmax but it seems rather aimed towards dealing with class imbalance in the learning set, so I don't see how it could help here but I might miss it ;) |
@yannclaes ahah,yeah. Everyone is working to improve AP.Thank you again. |
@SpongeBab @yannclaes yes that is correct. You can train multiple datasets simultaneously by adding them to the train and val fields of your dataset.yaml as a list. All the datasets in the list must share common class naming convention though, so for example if you want to train classes in addition to coco you can add your custom dataset to the train/val lists, making sure it's class indices start at 80. GlobalWheat2020.yaml is a good example of grouping multiple datasets togethor: yolov5/data/GlobalWheat2020.yaml Lines 9 to 27 in 0e2f2cb
|
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Access additional YOLOv5 🚀 resources:
Access additional Ultralytics ⚡ resources:
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 YOLOv5 🚀 and Vision AI ⭐! |
@SpongeBab hello ! |
i have already model object detection modle in yolov8 with 25 classes and now i want to add new label 26 th i want to train that exciting model with new class only i want to train only new class images not that others 25 already train but i want to updated model with 26 classes is there any way to this |
Hello @mariswarycharan, To add a new class to your existing YOLOv8 model with 25 classes, you will need to follow a few steps to ensure the model is updated correctly. Here’s a concise guide to help you achieve this:
Here’s a code snippet to illustrate the training process: import torch
from yolov5 import train
# Load the pre-trained model
model = torch.hub.load('ultralytics/yolov5', 'custom', path='path/to/your/model.pt')
# Update the number of classes
model.nc = 26 # Update this to the new number of classes
model.names = ['class1', 'class2', ..., 'class26'] # Update with your class names
# Train the model on the new dataset
train.run(imgsz=640, epochs=10, data='path/to/your/dataset.yaml', weights='path/to/your/model.pt')
For more detailed instructions, you can refer to the YOLOv5 documentation. If you encounter any issues during this process, please ensure you are using the latest versions of the packages and feel free to reach out with specific questions. Good luck with your training! 🚀 |
But while detection ,the model is not detecting the previous classes it only detects the new classes |
Hello @Gnanapriya2000 yes this is normal. Any classes not present in the new training will naturally not be learned. |
❔Question
How can I train one or several new classes on top of an existing training set.
Additional context
For example,If I have a new dataset, and I want to add the new class on the trained COCO weights.Um.....What I should do or is there any guide?
The text was updated successfully, but these errors were encountered: