Giter VIP home page Giter VIP logo

Comments (3)

glenn-jocher avatar glenn-jocher commented on July 3, 2024

@IgorGoldberg hello,

Thank you for your kind words and for reaching out with your question! 😊

To ensure that your Oriented Bounding Box (OBB) labels are correctly formatted and understood by YOLOv8, you can indeed perform a few checks beyond just inferencing. Here are some steps you can follow:

  1. Visualize the Labels: Before training or inferencing, you can visualize the OBB labels on your images to ensure they are correctly placed. This can be done using a simple script to draw the bounding boxes based on your label files.

    import cv2
    import matplotlib.pyplot as plt
    
    def draw_obb(image_path, label_path):
        image = cv2.imread(image_path)
        with open(label_path, 'r') as file:
            for line in file:
                parts = line.strip().split()
                cls, points = int(parts[0]), list(map(float, parts[1:]))
                points = [(int(points[i] * image.shape[1]), int(points[i+1] * image.shape[0])) for i in range(0, len(points), 2)]
                points = np.array(points, np.int32).reshape((-1, 1, 2))
                cv2.polylines(image, [points], isClosed=True, color=(0, 255, 0), thickness=2)
        plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
        plt.show()
    
    draw_obb('path/to/your/image.jpg', 'path/to/your/label.txt')
  2. Run a Small Training Session: Train your model on a small subset of your dataset and validate the results. This can help you quickly identify any issues with the labels without committing to a full training session.

    yolo detect train data=your_dataset.yaml model=yolov8n-obb.yaml epochs=10 imgsz=640
  3. Check for Errors in Conversion: If you converted your dataset from another format (e.g., DOTA to YOLO OBB), ensure that the conversion script ran without errors and that the output files are correctly formatted.

    from ultralytics.data.converter import convert_dota_to_yolo_obb
    convert_dota_to_yolo_obb("path/to/DOTA")
  4. Inference on a Few Samples: Perform inference on a few sample images to visually inspect the predictions. This can help you confirm that the model is interpreting the labels correctly.

    yolo detect predict model=your_trained_model.pt source='path/to/sample_image.jpg'

By following these steps, you can confidently verify that your OBB labels are correctly formatted and understood by YOLOv8. If you encounter any issues, please ensure you are using the latest versions of torch and ultralytics packages. If the problem persists, feel free to share a minimum reproducible example so we can assist you further. You can find more details on creating a reproducible example here.

Best of luck with your project, and feel free to reach out if you have any more questions!

from ultralytics.

IgorGoldberg avatar IgorGoldberg commented on July 3, 2024

Thank you very much for the answer.
Regarding the first way to check, sounds like a good idea, but are you sure that this way fits specifically for checking the
L2>L1 vs L2<L1 cases?
I am asking this since as far as I remember drawing a polyline with CV2 takes just a points coordinates without any importance which point is the first one, while in yolov8 OBB this seems to be an issue.

from ultralytics.

glenn-jocher avatar glenn-jocher commented on July 3, 2024

Hello @IgorGoldberg,

Thank you for your follow-up! 😊

You're correct that the order of points is crucial for OBBs in YOLOv8, especially for distinguishing between L2 > L1 and L2 < L1 cases. To ensure the correct order, you can modify the visualization script to explicitly handle the point order as defined in your labels.

Here's an updated version of the script that considers the point order:

import cv2
import numpy as np
import matplotlib.pyplot as plt

def draw_obb(image_path, label_path):
    image = cv2.imread(image_path)
    with open(label_path, 'r') as file:
        for line in file:
            parts = line.strip().split()
            cls, points = int(parts[0]), list(map(float, parts[1:]))
            points = [(int(points[i] * image.shape[1]), int(points[i+1] * image.shape[0])) for i in range(0, len(points), 2)]
            points = np.array(points, np.int32).reshape((-1, 1, 2))
            cv2.polylines(image, [points], isClosed=True, color=(0, 255, 0), thickness=2)
    plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
    plt.show()

draw_obb('path/to/your/image.jpg', 'path/to/your/label.txt')

This script ensures that the points are drawn in the order they appear in your label file, which should help you verify the correct orientation.

If you encounter any issues or need further assistance, please ensure you are using the latest versions of torch and ultralytics. If the problem persists, providing a minimum reproducible example would be very helpful for us to investigate further. You can find more details on creating a reproducible example here.

Best of luck with your project, and feel free to reach out if you have any more questions!

from ultralytics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.