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

Need advice for training a YOLOv5-obb model #12959

Open
1 task done
yasmine-lkl opened this issue Apr 24, 2024 · 6 comments
Open
1 task done

Need advice for training a YOLOv5-obb model #12959

yasmine-lkl opened this issue Apr 24, 2024 · 6 comments
Labels
question Further information is requested

Comments

@yasmine-lkl
Copy link

yasmine-lkl commented Apr 24, 2024

Search before asking

Question

Hello,

I'm currently working on my internship project focusing on object detection in images captured by drones. I'm facing some challenges and would like to seek your advice and suggestions.

Firstly, the objects I'm aiming to detect are quite small, and I haven't found a pre-trained dataset that matches my requirements online. To overcome this challenge, I've decided to use YOLOv5-obb and have started annotating my images on Roboflow. I'd like to emphasize that I'm using instance segmentation instead of traditional object detection on Roboflow. This decision allows me to leverage the "polygon tool" for accurate object orientation. When I export my annotations, they will be in the "oriented bounding boxes YOLOv5" format.

However, the annotation process is taking a significant amount of time, and I'm wondering if annotating 150 to 200 images would be sufficient to train my model and achieve effective results. Additionally, I'm a novice in using YOLO, and I'm seeking advice on how to optimize my model.

If you have any recommendations, tips, or methods to improve the efficiency of my model, I would be extremely grateful to hear them.

Thank you in advance for your valuable assistance.

Additional

No response

@yasmine-lkl yasmine-lkl added the question Further information is requested label Apr 24, 2024
@glenn-jocher
Copy link
Member

@yasmine-lkl hello! 🚀

Great to hear about your project and your proactive steps with YOLOv5-obb for drone-captured image detection. Training models on small objects is a known challenge, but your approach is commendable.

For small datasets like yours (150-200 images), ensuring high-quality annotations is key. The more precise your annotations, especially with oriented bounding boxes (OBB), the better your results will likely be. However, the size of your dataset is indeed small, which can impact the model's effectiveness. To enhance your model's performance, consider:

  1. Augmentation: Make full use of data augmentation to artificially expand your dataset. Experiment with different types to see what works best for your specific case.
  2. Transfer Learning: Start with a pre-trained model and fine-tune it on your dataset. This can significantly reduce the amount of data required for effective training.
  3. Iterative Training: Begin training with what you have and iteratively add more data if possible. This can help you gauge the model's performance and understand if more data is needed.
  4. Model Selection: For small objects, you might need to adjust the model's architecture. Consider experimenting with different versions of YOLOv5 (e.g., YOLOv5s, YOLOv5m) to find the best fit.

Remember, the journey to an optimal model often involves a lot of trial and testing. Keep experimenting with different configurations, and don't hesitate to revisit your dataset for possible improvements.

Best of luck with your project! If you have more questions or need further assistance, feel free to ask. 🌟

@yasmine-lkl
Copy link
Author

@glenn-jocher Thank you so much for taking the time to respond to my message and for your invaluable advice! 🙏

I'm thrilled to hear your suggestions regarding data augmentation. Is it possible to perform data augmentation directly on Roboflow? Additionally, I'm considering using tiling to zoom in on my photos, but I'm concerned about how this might affect the annotations. Do you have any solutions for this issue?

I'm also curious about integrating other methods such as self-supervised learning or cross-validation to optimize my model. Would these approaches be beneficial in my case?

Adding pre-trained data isn't feasible since the objects I aim to detect, such as Velux windows, chimneys, and ventilation systems, aren't found in pre-trained datasets.

Ultimately, my goal is to test the tool on orthophotos and integrate it into AutoCAD software for automatic detection of objects in orthophotos. If you have any further advice or suggestions, I would be incredibly grateful!

Thank you once again for your support and guidance. 🚀

@yasmine-lkl
Copy link
Author

yasmine-lkl commented May 20, 2024

@yasmine-lkl hello! 🚀

Great to hear about your project and your proactive steps with YOLOv5-obb for drone-captured image detection. Training models on small objects is a known challenge, but your approach is commendable.

For small datasets like yours (150-200 images), ensuring high-quality annotations is key. The more precise your annotations, especially with oriented bounding boxes (OBB), the better your results will likely be. However, the size of your dataset is indeed small, which can impact the model's effectiveness. To enhance your model's performance, consider:

  1. Augmentation: Make full use of data augmentation to artificially expand your dataset. Experiment with different types to see what works best for your specific case.
  2. Transfer Learning: Start with a pre-trained model and fine-tune it on your dataset. This can significantly reduce the amount of data required for effective training.
  3. Iterative Training: Begin training with what you have and iteratively add more data if possible. This can help you gauge the model's performance and understand if more data is needed.
  4. Model Selection: For small objects, you might need to adjust the model's architecture. Consider experimenting with different versions of YOLOv5 (e.g., YOLOv5s, YOLOv5m) to find the best fit.

Remember, the journey to an optimal model often involves a lot of trial and testing. Keep experimenting with different configurations, and don't hesitate to revisit your dataset for possible improvements.

Best of luck with your project! If you have more questions or need further assistance, feel free to ask. 🌟

Hello again,

I am reaching out for your guidance regarding an issue I am encountering with my YOLOv8-obb model.

Here is a summary of my training process:

I manually annotated 200 images.
I used Roboflow for data augmentation, increasing the total number of images to 500.
The objects I aim to detect are very small, which necessitated the use of augmentation.
During the training and validation phases, the results appeared promising. However, I am experiencing an issue during the testing phase. Specifically, I consistently receive the message "No detections were found in the image" for all my test images. Below is the script I used for testing:

model = YOLO('/content/runs/obb/train/weights/best.pt')
import os
import random

images_directory = "/content/datasets/roboflow/test/images"

if os.path.exists(images_directory):
# Randomly select a file from the directory
random_file = random.choice(os.listdir(images_directory))
file_name = os.path.join(images_directory, random_file)

results = model(file_name)
if results[0] is not None:
    import supervision as sv
    import cv2


    if hasattr(results[0], 'boxes') and hasattr(results[0].boxes, 'cls'):
        detections = sv.Detections.from_ultralytics(results[0])
        oriented_box_annotator = sv.OrientedBoxAnnotator()
        annotated_frame = oriented_box_annotator.annotate(
            scene=cv2.imread(file_name),
            detections=detections
        )
        sv.plot_image(image=annotated_frame, size=(16, 16))
    else:
        print("No detections were found in the image.")
else:
    print("No detections were found in the image.")

else:
print(f"{images_directory} doesn't exist")

Despite the seemingly successful training and validation, the above script yields no detections for my test images. Is this behavior normal? Could you provide any recommendations on what I might modify to achieve better results?

Additionally, I am considering integrating methods like cross-validation, self-supervised learning, or SAHI. Are these approaches supported by YOLOv8-obb, and would you recommend their usage in this context?

Thank you in advance for your assistance. I look forward to your insights.

Best regards

R_curve
P_curve
PR_curve
F1_curve

@glenn-jocher
Copy link
Member

@yasmine-lkl hello,

It sounds like you're making great progress with your YOLOv8-obb model, but encountering a hiccup during testing is indeed frustrating.

Given that your training and validation phases showed promising results but no detections are found during testing, here are a few things to consider:

  1. Threshold Settings: Check if the confidence threshold is set too high during testing, which might be filtering out potential detections. Try lowering the threshold to see if it captures more detections.

  2. Model Overfitting: Even though training and validation look good, the model might not generalize well to new data. Consider adding more variety to your training data or using techniques like dropout or regularization during training.

  3. Data Preprocessing: Ensure that the preprocessing steps (like normalization) applied to the training data are exactly the same during testing. Any discrepancy here can lead to poor model performance on test data.

  4. Test Data Quality: Verify that the test images are similar in quality and characteristics to the training images. Differences in image quality, resolution, or object sizes can affect detection.

Regarding integrating methods like cross-validation, self-supervised learning, or SAHI, these are advanced techniques that can potentially improve model robustness:

  • Cross-validation can help in understanding how well your model generalizes across different subsets of your data.
  • Self-supervised learning could be beneficial if labeled data is scarce, but it requires careful implementation.
  • SAHI is a tool for slicing large images into smaller, manageable pieces, which can be particularly useful if your test images are significantly larger or different from training images.

Experimenting with these methods depends on your specific needs and the complexity you're ready to manage. Keep iterating and fine-tuning based on the results you observe.

Best of luck, and keep pushing forward! 🚀

@yasmine-lkl
Copy link
Author

@yasmine-lkl hello,

It sounds like you're making great progress with your YOLOv8-obb model, but encountering a hiccup during testing is indeed frustrating.

Given that your training and validation phases showed promising results but no detections are found during testing, here are a few things to consider:

  1. Threshold Settings: Check if the confidence threshold is set too high during testing, which might be filtering out potential detections. Try lowering the threshold to see if it captures more detections.
  2. Model Overfitting: Even though training and validation look good, the model might not generalize well to new data. Consider adding more variety to your training data or using techniques like dropout or regularization during training.
  3. Data Preprocessing: Ensure that the preprocessing steps (like normalization) applied to the training data are exactly the same during testing. Any discrepancy here can lead to poor model performance on test data.
  4. Test Data Quality: Verify that the test images are similar in quality and characteristics to the training images. Differences in image quality, resolution, or object sizes can affect detection.

Regarding integrating methods like cross-validation, self-supervised learning, or SAHI, these are advanced techniques that can potentially improve model robustness:

  • Cross-validation can help in understanding how well your model generalizes across different subsets of your data.
  • Self-supervised learning could be beneficial if labeled data is scarce, but it requires careful implementation.
  • SAHI is a tool for slicing large images into smaller, manageable pieces, which can be particularly useful if your test images are significantly larger or different from training images.

Experimenting with these methods depends on your specific needs and the complexity you're ready to manage. Keep iterating and fine-tuning based on the results you observe.

Best of luck, and keep pushing forward! 🚀

Hello again :)

I wanted to share with you the results I've obtained while testing yolov8x-obb. Enclosed is a screenshot illustrating the outcomes, showing a somewhat satisfactory detection of objects. Notably, I haven't implemented any of the methods I proposed in my previous comment. Consequently, I'm uncertain whether to assert that my model effectively detects objects and proceed to deployment or if further optimization is necessary.

My primary query revolves around determining whether my model is adequately optimized and how I can manipulate hyperparameters to achieve optimization. While I understand the concept of commencing with a relatively high learning rate and subsequently decreasing it after a certain number of epochs, I'm unsure about the specifics. Should I provide a precise initial learning rate (lr0), and will the model automatically adjust it after each epoch? Additionally, I seek guidance on selecting the appropriate batch size and other hyperparameters, as well as interpreting the resultant curves.

I genuinely appreciate your assistance and guidance in aiding community to progress in this field. Your insights have been invaluable, and I am sincerely grateful for your ongoing support.
100_0007_0177_JPG rf 0e11e006f811984366cfcfe4af06db8c
F1_curve
P_curve
PR_curve
R_curve
results

@glenn-jocher
Copy link
Member

Hello @yasmine-lkl,

Great to see your progress with the YOLOv8x-obb model! From your results, it looks like you're on the right track.

Regarding optimization and deployment:

  • Model Optimization: If the detection results are satisfactory and consistent across various test scenarios, you might consider the model ready for the next stage. However, if you notice variability or specific scenarios where performance dips, further tuning might be necessary.
  • Learning Rate (lr0): Starting with a higher learning rate and reducing it can help the model converge faster initially and then fine-tune more delicately. You can set an initial learning rate using --lr0 and manage its decay with --lrf in your training command. The model will adjust the learning rate based on these settings.
  • Batch Size and Hyperparameters: A larger batch size generally provides more stable and accurate gradient estimates, but it's limited by your hardware capabilities. Start with the largest batch size your hardware can handle and adjust if necessary. For other hyperparameters, it's often effective to start with the defaults provided by YOLOv5 and only tweak them if specific issues arise.
  • Interpreting Curves: The F1, Precision (P), Recall (R), and PR curves provide insights into model performance. High F1 scores and balanced P and R curves typically indicate good model performance. If the PR curve shows a steep drop or if the F1 curve is low, consider adjusting class weights or augmentation strategies.

Keep testing with varied data to ensure robustness before full deployment. Your diligence in refining the model will pay off!

Best of luck, and keep up the great work! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants