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

Labelme2Yolo ? #57

Open
monkeycc opened this issue Nov 20, 2023 · 5 comments
Open

Labelme2Yolo ? #57

monkeycc opened this issue Nov 20, 2023 · 5 comments

Comments

@monkeycc
Copy link

Labelme
polygon, rectangle, circle

@glenn-jocher
Copy link
Member

@monkeycc hi there! Thanks for reaching out. Labelme2Yolo isn't currently included in the Ultralytics YOLO repository, but you can easily convert Labelme annotations to YOLO format using your own script or tools like labelme2coco followed by COCO to YOLO conversion. Check out the Ultralytics Docs for more details. If you have any other questions, feel free to ask!

@Harry-KIT
Copy link

Hi @glenn-jocher, my question is also similar with others. But I have labeled image like below:

{
"version": "5.4.1",
"flags": {},
"shapes": [
{
"label": "food",
"points": [
[
239.0,
196.0
],
[
285.0,
297.0
]
],
"group_id": null,
"description": "",
"shape_type": "mask",
"flags": {},
"mask": "iVBORw0KGgoAAAANSUhEUgAAAC8AAABmAQAAAABzC/WlAAAAxUlEQVR4nI2RwRGCMBBFX3YY5SYdSCfSlicpLSVYAiVw4MABEg8fhVUcPb15f7NJNoFjBIwyAnACMGiF5gAG9TUCp5w7DLSkgmq1BfXLyo8aUOyFC0wIa9gA7feGNzRCLVSuVr4s7rV3qxUhJGA2qRVCuWmwt/bq9wXrP2fAmo0lV5ucjULvwk6I2zDrBZM7aBB6YfnUKLQYMGvlJIzCHUKGAAZZmyU3w+RsdNY76z5nb58WAW55U+OSATgnhUI/ANhwB3gAGE8tVLpKku0AAAAASUVORK5CYII="
},
{
"label": "food",
"points": [
[
159.0,
137.0
],
[
177.0,
166.0
]
],
"group_id": null,
"description": "",
"shape_type": "mask",
"flags": {},
"mask": "iVBORw0KGgoAAAANSUhEUgAAABMAAAAeAQAAAADmtRi/AAAASElEQVR4nEXKsRFAQABE0XdLESJDJ9cZpdGJEoSyEzBE+//8ZRSzqAKaFGtCejKomUglKM0eDweWdny+vXv8PaenX++/a5TTDZA+DWjnicmcAAAAAElFTkSuQmCC"
},
.....
.....
"imagePath": "gray-a-0-0.jpg",
"imageData": ......
"imageHeight": 640,
"imageWidth": 640
}

I couldn't find any sources to convert its mask to yolo format

@glenn-jocher
Copy link
Member

Hello @Harry-KIT! Converting Labelme mask annotations to YOLO format requires a custom script since YOLO expects bounding boxes rather than masks. You'll need to:

  1. Load the mask from the "mask" field in your Labelme JSON.
  2. Convert the mask to a binary format if it's not already.
  3. Calculate the bounding box coordinates from the binary mask.
  4. Normalize the bounding box coordinates relative to the image width and height.
  5. Save the normalized coordinates in YOLO format: <class_id> <x_center> <y_center> <width> <height>.

For each object, the <class_id> is an integer that corresponds to the index of the object class in your classes list. <x_center>, <y_center>, <width>, and <height> are the center coordinates, width, and height of the bounding box, all normalized by the image width and height (values between 0 and 1).

Please refer to the Ultralytics Docs for more information on the YOLO format. If you need further assistance, don't hesitate to ask. Good luck with your project! 😊👍

@Harry-KIT
Copy link

Hello @glenn-jocher, Thank you very much

@glenn-jocher
Copy link
Member

You're welcome, @Harry-KIT! If you have any more questions or need further assistance as you work on your project, feel free to reach out. Happy coding, and best of luck with your work! 😊🚀

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

No branches or pull requests

3 participants