ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
50.65k stars 16.33k forks source link

Need advice for training a YOLOv5-obb model #12959

Closed yasmine-lkl closed 3 months ago

yasmine-lkl commented 6 months ago

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

glenn-jocher commented 6 months ago

@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 commented 6 months ago

@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 commented 5 months ago

@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 commented 5 months ago

@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:

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 commented 5 months ago

@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 commented 5 months ago

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:

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! 🚀

yasmine-lkl commented 5 months ago

Hello @glenn-jocher

I wanted to provide you with an update on the deployment of my YOLOv8-OBB model. I'm working on deploying the model using Tkinter for the user interface.

However, I've encountered an issue during the deployment process. When I run the deployment script, the bounding boxes that appear after the detection in the interface are not oriented. To provide some context, I've trained this version of the YOLOv8 model on Roboflow, and during testing on the Roboflow platform, the bounding boxes were correctly oriented.

I'm reaching out to you for assistance as you may have insights or information regarding this issue. If there are any known solutions or if you could offer guidance on troubleshooting this problem, it would be greatly appreciated.

Thank you for your attention to this matter, and I look forward to hearing from you soon.

Best regards

glenn-jocher commented 5 months ago

Hello,

Thank you for the update on deploying your YOLOv8-OBB model with Tkinter. It's great to hear about your progress!

Regarding the issue with non-oriented bounding boxes, it sounds like there might be a discrepancy in how the bounding box coordinates are being handled or displayed in your Tkinter interface compared to Roboflow.

Here are a few steps you can take to troubleshoot:

  1. Verify Coordinate Handling: Ensure that the coordinates extracted from the model's output are being correctly interpreted and used in your Tkinter application.
  2. Check Visualization Code: Sometimes, the issue might be with the visualization logic in Tkinter. Make sure that the code responsible for drawing the bounding boxes on the interface can handle and render oriented boxes.
  3. Model Output Review: Double-check the model outputs directly before they are passed to the Tkinter interface to confirm that the orientation data is present and correct.

If these steps don't resolve the issue, it might be helpful to look into the specific code segments handling the bounding box rendering in Tkinter for further clues.

Best of luck, and I hope this helps!

github-actions[bot] commented 4 months ago

👋 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 ⭐