ultralytics / JSON2YOLO

Convert JSON annotations into YOLO format.

Home Page:https://docs.ultralytics.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Labelme2Yolo ?

monkeycc opened this issue Β· comments

Labelme
polygon, rectangle, circle

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

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

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! πŸ˜ŠπŸ‘

Hello @glenn-jocher, Thank you very much

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! πŸ˜ŠπŸš€