GithubHelp home page GithubHelp logo

Comments (1)

makseq avatar makseq commented on September 26, 2024

Label Studio does not have built-in support for the Labelme JSON format. However, you can convert the Labelme JSON format to the Label Studio JSON format using a custom script. Here's an example of how you can do this:

  1. First, let's assume you have a Labelme JSON file named labelme_annotations.json with the following content:
{
  "shapes": [
    {
      "label": "dog",
      "points": [
        [100, 100],
        [200, 100],
        [200, 200],
        [100, 200]
      ]
    },
    {
      "label": "cat",
      "points": [
        [300, 300],
        [400, 300],
        [400, 400],
        [300, 400]
      ]
    }
  ],
  "imagePath": "example.jpg"
}
  1. Create a Python script named convert_labelme_to_labelstudio.py with the following content:
import json

def convert_labelme_to_labelstudio(labelme_json):
    labelstudio_json = {
        "image": labelme_json["imagePath"],
        "annotations": []
    }

    for shape in labelme_json["shapes"]:
        annotation = {
            "id": len(labelstudio_json["annotations"]) + 1,
            "type": "rectanglelabels",
            "value": {
                "x": shape["points"][0][0],
                "y": shape["points"][0][1],
                "width": shape["points"][1][0] - shape["points"][0][0],
                "height": shape["points"][2][1] - shape["points"][1][1],
                "rectanglelabels": [shape["label"]]
            }
        }
        labelstudio_json["annotations"].append(annotation)

    return labelstudio_json

if __name__ == "__main__":
    with open("labelme_annotations.json", "r") as f:
        labelme_json = json.load(f)

    labelstudio_json = convert_labelme_to_labelstudio(labelme_json)

    with open("labelstudio_annotations.json", "w") as f:
        json.dump(labelstudio_json, f, indent=2)
  1. Run the script to convert the Labelme JSON file to the Label Studio JSON format:
python convert_labelme_to_labelstudio.py
  1. The script will create a new file named labelstudio_annotations.json with the following content:
{
  "image": "example.jpg",
  "annotations": [
    {
      "id": 1,
      "type": "rectanglelabels",
      "value": {
        "x": 100,
        "y": 100,
        "width": 100,
        "height": 100,
        "rectanglelabels": [
          "dog"
        ]
      }
    },
    {
      "id": 2,
      "type": "rectanglelabels",
      "value": {
        "x": 300,
        "y": 300,
        "width": 100,
        "height": 100,
        "rectanglelabels": [
          "cat"
        ]
      }
    }
  ]
}
  1. Now you can import the labelstudio_annotations.json file into Label Studio.

Please note that this example assumes you are working with rectangular bounding boxes. You might need to adjust the script to handle other annotation types supported by Labelme and Label Studio.

from label-studio-converter.

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.