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

How to convert segment json data labeled by labelme to yolo format? #12841

Closed
1 task done
fewshotstudy opened this issue Mar 23, 2024 · 4 comments
Closed
1 task done
Labels
question Further information is requested Stale

Comments

@fewshotstudy
Copy link

Search before asking

Question

How to convert segment json data labeled by labelme to yolo format?
Can you share some details code?

Additional

No response

@fewshotstudy fewshotstudy added the question Further information is requested label Mar 23, 2024
@glenn-jocher
Copy link
Member

@fewshotstudy hello! 😊 Converting label formats is a common task. While we don't have a direct feature in YOLOv5 for converting LabelMe JSON to YOLO format, the general process involves parsing the JSON file to extract bounding box coordinates and then saving them in the YOLO format.

Here's a simplified code outline to get you started:

import json

def convert_labelme_to_yolo(json_path, output_path):
    with open(json_path) as f:
        data = json.load(f)
    # Assuming one object per file for simplicity
    width, height = data['imageWidth'], data['imageHeight']
    for shape in data['shapes']:
        label = shape['label']
        points = shape['points'] # Assuming rectangle: top-left and bottom-right
        x1, y1 = points[0]
        x2, y2 = points[1]
        # Convert to YOLO format
        x_center = (x1 + x2) / 2 / width
        y_center = (y1 + y2) / 2 / height
        w = abs(x2 - x1) / width
        h = abs(y2 - y1) / height
        # Save to file
        with open(output_path, 'a') as f:
            f.write(f'{label} {x_center} {y_center} {w} {h}\n')

# Example usage
convert_labelme_to_yolo('path/to/your/labelme.json', 'path/to/output.txt')

Please adjust the code to your specific needs, especially if you have multiple objects per image or other shape types. Happy coding! 🚀

@fewshotstudy
Copy link
Author

Thank you.Sir!
I make it!

@glenn-jocher
Copy link
Member

Fantastic news, @fewshotstudy! 😊 Great to hear you've achieved what you set out to do. If you have more questions or need further assistance down the road, feel free to reach out. Happy developing with YOLOv5! 🚀

Copy link
Contributor

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

@github-actions github-actions bot added the Stale label Apr 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants