ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
24.46k stars 4.86k forks source link

YOLOv8 classification #12737

Open bezakovabarbora opened 2 weeks ago

bezakovabarbora commented 2 weeks ago

Search before asking

Question

Hello, I have gone through several questions to get answer to my question. I found that validation set is not used in training in any way. But... I am training a yolov8n-cls.pt on AI generated images. When I use those generated data as validation set, the results for real data are worse than when I use real-world data as validation set. Why is that? confusion_matrix_normalized

confusion_matrix_normalized_2

Additional

No response

github-actions[bot] commented 2 weeks ago

👋 Hello @bezakovabarbora, 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.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If 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.

glenn-jocher commented 2 weeks ago

@bezakovabarbora hello! It seems like you're noticing differences in model performance based on the type of data used for validation. This typically happens when there's a significant difference between the distribution of your training data and validation data, especially evident when using AI-generated images versus real-world images.

AI-generated data might not comprehensively capture the variability and complexity found in real-world data. This discrepancy can lead the model to overfit to the characteristics of the generated images, which might not generalize well to real-world scenarios, thus performing poorly when real data is introduced.

To mitigate this, try to ensure the AI-generated data closely mirrors the real-world data in terms of distribution and characteristics. Also, regularly validate with a mix of both real and generated data can give you a better insight into how well the model might perform in actual applications. Here's a snippet to set up your validation process to include both types of data:

from ultralytics import YOLO

# Load the model
model = YOLO('yolov8n-cls.pt')

# Train the model using both generated and real-world images
results = model.train(data='combined_data.yaml', epochs=100, imgsz=640)

# Evaluate the model
metrics = model.val()

Make sure combined_data.yaml contains paths to both your AI-generated and real-world validation datasets. This approach can help achieve more robust generalization. Hope this helps! 🚀

bezakovabarbora commented 2 weeks ago

@glenn-jocher Thank you for your response. I understand that the photos are from different distribution, I will try to combine it. Does YOLO use the validation set in the training process to adjust the parameters during training?

glenn-jocher commented 1 week ago

Hello @bezakovabarbora! Great to hear that you'll try combining the datasets. Regarding your question, YOLO does not use the validation set to adjust the model's parameters during training. The validation set is solely used to evaluate the model's performance after each epoch, ensuring that the model generalizes well to new, unseen data without influencing the training process directly. This helps in monitoring for overfitting and tuning hyperparameters effectively. Let me know if you need further clarification! 😊