-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
How to Train model with different dataset contain different classes #12697
Comments
👋 Hello @Vinaygoudasp7, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users. InstallPip install the pip install ultralytics EnvironmentsYOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
i have searched but i didnt get similar question so can you provide ans to clarify my doubt |
Hello! Thanks for reaching out with your question. Yes, you can sequentially train your model on different datasets, but this may not be the most effective approach if the datasets involve distinctly different classes. Each subsequent training might overwrite or forget the previously learned classes (a phenomenon known as catastrophic forgetting). A better approach would be to merge all datasets into a single one and train your model from scratch on this combined set. This helps the model learn features from all classes at once, improving its overall generalization. Here’s a simple way to combine datasets:
Example YAML setup might look like this: # combined_dataset.yaml
train: ./data/combined_train/
val: ./data/combined_val/
nc: 10 # Total number of classes
names: ['class1', 'class2', ..., 'class10'] Then, you can start training: yolo detect train data=combined_dataset.yaml model=yolov8n.yaml I hope this helps! Let me know if you have any more questions. |
thank you for given solution and think it should be effective for few number of dataset but is there any different approach to train model with different dataset and is it work if i transfer weight of previous model |
Hello! Glad the initial solution was helpful. 😊 For training on multiple datasets with different classes, another effective method is using incremental learning or transfer learning where you transfer weights from a previously trained model. Here’s a concise approach:
yolo detect train data=new_dataset.yaml model=previous_best.pt Just be cautious with the class labels to ensure consistency across datasets. Each training phase should ideally include samples (even if few) from the previous classes to prevent forgetting. This method can help the model learn new classes while retaining knowledge about the old ones. Keep in touch if you need more clarifications! |
Maybe this will help you! Extending YOLOv8 COCO Model With New Classes Without Affecting Old Weights |
@glenn-jocher thank you for solution if possible you can mention how can i add class in data.yaml file and it helpfull @y824165978 thank you also for sloution |
Hello! I'm glad you found the solutions helpful! 😊 To add a class in your nc: 4 # number of classes
names: ['class1', 'class2', 'class3', 'new_class'] Make sure that the annotations in your dataset correspond to these class labels by index. Let me know if you need further assistance! |
@glenn-jocher thanks a lot for giving detailed solution for my problem , its help to me |
you told to update data.yaml file, data.yaml of new dataset |
Hello! Yes, you should update the train: path/to/new/train/images
val: path/to/new/val/images
nc: number_of_classes_including_new_ones
names: ['class1', 'class2', ..., 'new_class'] Just replace the paths and class details as needed for your new dataset. This setup ensures that your model learns from the new data while leveraging the knowledge gained from previous training. 😊 |
@glenn-jocher ok thank you for previous answer it works and can i train yolo-world model with custom dataset and how |
Load a pretrained YOLOv8s-worldv2 model and train it on the COCO8 example dataset for 100 epochs!yolo train model=yolov8s-worldv2.pt data=D:/AIML/YOLO_Object_detection/Pen_book_detection-1/data.yaml epochs=30 imgsz=640 data.yaml
nc: 82 roboflow:license: CC BY 4.0project: pen_book_detection-bhnvgurl: https://universe.roboflow.com/vinay-yeadc/pen_book_detection-bhnvg/dataset/1version: 1workspace: vinay-yeadctest: ./test/images is it correct for traing with new dataset by including old class name and it not working can you tell me this video_stream=VideoStream(0).start() video_stream=cv2.VideoCapture('./images_videos/7648337-hd_1920_1080_30fps.mp4')device='cuda' if torch.cuda.is_available() else 'cpu' model.set_classes(['cup','bottel'])while True:
cv2.destroyAllWindows() |
Hello! It looks like you're on the right track with your training setup and the use of the YOLO-World model. However, if you're experiencing issues, here are a few things to check:
For the video stream processing code, it seems mostly correct. If the model isn't performing as expected, it might be due to how the model was trained or possibly an issue with how the frames are being processed or resized. If you continue to face issues, please provide any error messages or specific behaviors that are not working as expected. This will help in diagnosing the problem more effectively. 😊 |
i am not geting any error i am training by using cmd !yolo train model=yolov8s-worldv2.pt data=D:/AIML/YOLO_Object_detection/Pen_book_detection-1/data.yaml epochs=30 imgsz=640 it gives best.pt file then i want to use to predict object but it not working as accepted |
@Vinaygoudasp7 hello! It sounds like you've successfully trained your model but are having issues with the predictions. To help you better, could you please clarify what you mean by "not working as expected"? Are you seeing incorrect detections, or is there another issue during prediction? For predictions, ensure you're loading the from ultralytics import YOLO
# Load your trained model
model = YOLO('path/to/best.pt')
# Run prediction
results = model.predict('path/to/your/image.jpg')
results.show() # To display the image with predictions Make sure the path to |
model.set_classes( ['Book' 'Pen' 'person' 'bicycle' 'car' 'motorcycle' 'airplane' 'bus' 'train' 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'dining table', 'toilet', frame= video_stream.read()
{0: 'Book', 1: 'Pen', 2: 'person', 3: 'bicycle', 4: 'car', 5: 'motorcycle', 6: 'airplane', 7: 'bus', 8: 'train', 9: 'truck', 10: 'boat', 11: 'traffic light', 12: 'fire hydrant', 13: 'stop sign', 14: 'parking meter', 15: 'bench', 16: 'bird', 17: 'cat', 18: 'dog', 19: 'horse', 20: 'sheep', 21: 'cow', 22: 'elephant', 23: 'bear', 24: 'zebra', 25: 'giraffe', 26: 'backpack', 27: 'umbrella', 28: 'handbag', 29: 'tie', 30: 'suitcase', 31: 'frisbee', 32: 'skis', 33: 'snowboard', 34: 'sports ball', 35: 'kite', 36: 'baseball bat', 37: 'baseball glove', 38: 'skateboard', 39: 'surfboard', 40: 'tennis racket', 41: 'bottle', 42: 'wine glass', 43: 'cup', 44: 'fork', 45: 'knife', 46: 'spoon', 47: 'bowl', 48: 'banana', 49: 'apple', 50: 'sandwich', 51: 'orange', 52: 'broccoli', 53: 'carrot', 54: 'hot dog', why the result not geting and i used base model as |
can i use pretrained yolov8s_worldv2.pt for training the custom dataset and also while training yolo world by using custom dataset it creates some images of train_batch.jpg in runs directory it labeled with different classes other than like the pen image it labeled with other classes in data.yaml classes as per previous data.yaml file or as per previous prompt why like this as shown below and also other classes are not reflected in new trained model best.pt after training i get like this Validating runs\detect\train36\weights\best.pt... |
Hello! Yes, you can use the pretrained Regarding the
For the issue of other classes not being reflected in the new trained model, it's important to include a representative sample of all desired classes during training to avoid class imbalance and ensure the model learns to recognize all of them effectively. If you continue to see unexpected results, consider reviewing your dataset and annotations for consistency and accuracy. Happy training! 😊 |
names:
nc: 82 |
@Vinaygoudasp7 hello! Your |
hi i get anther doubt can i use this command to train !yolo detect train data=D:/AIML/Traffic_signal_and_violation_detections/trafficlights21/data.yaml model=yolov8m-worldv2.pt epochs=10 imgsz=640 freeze=20 it is like in the yolov5 by freezeing some layer of trained previous dataset |
Hello! Yes, you can use the |
Search before asking
Question
Hi
i am new to Ai/Ml i am working on yolov8, i have to train this model from scratch so i have selected 3 dataset of different classes. my doubt if i train model from scratch by using yolov8n.yaml by using one of dataset then i train model which i got best.pt (from previous train) with next dataset can i do like this or if any alternate ways to solve this problem
Additional
No response
The text was updated successfully, but these errors were encountered: