Git Product home page Git Product logo

labelmeyoloconverter's Introduction

LabelMeYoloConverter

Convert LabelMe Annotation Tool JSON format to YOLO text file format. Tested for YOLOv3

Put your dataset (image and JSON format) in dataset/ Output will be saved in result/ JSON format will be moved to json_backup/

Finally, please manually copy text file together with image into 1 folder. (Intentionally separate the image and text output for maintainance purpose)

Example

JSON file

{
  "version": "3.8.1",
  "flags": {},
  "shapes": [
    {
      "label": "1",
      "line_color": null,
      "fill_color": null,
      "points": [
        [
          447,
          287
        ],
        [
          381,
          267
        ]
      ],
      "shape_type": "rectangle"
    }
  ],
  "lineColor": [
    0,
    255,
    0,
    128
  ],
  "fillColor": [
    255,
    0,
    0,
    128
  ],
  "imagePath": "-1289025526.jpg",
  "imageData": "iVBORw0KGgoAAAANSUhEUgAAA8AAAAIcCAIAA

Convterted to YOLO format text file

1 0.43125 0.512962962963 0.06875 0.037037037037

labelmeyoloconverter's People

Contributors

ivder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

labelmeyoloconverter's Issues

Polygon

how to convert if have polygon with four points?
for example:

{
"version": "4.5.6",
"flags": {},
"shapes": [
{
"label": "bro",
"points": [
[
676.686567164179,
708.9552238805969
],
[
687.1343283582089,
971.641791044776
],
[
666.2388059701491,
973.1343283582089
],
[
651.3134328358208,
710.4477611940298
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
585.641791044776,
194.02985074626864
],
[
628.9253731343283,
1020.8955223880596
],
[
609.5223880597015,
1019.4029850746268
],
[
570.7164179104477,
191.04477611940297
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
570.7164179104477,
189.55223880597015
],
[
609.5223880597015,
1022.3880597014925
],
[
591.6119402985074,
1020.8955223880596
],
[
554.2985074626865,
189.55223880597015
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
549.820895522388,
189.55223880597015
],
[
590.1194029850745,
1020.8955223880596
],
[
534.8955223880597,
1014.9253731343283
],
[
499.0746268656716,
201.49253731343282
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
499.0746268656716,
197.0149253731343
],
[
533.4029850746268,
1014.9253731343283
],
[
482.6567164179104,
1011.9402985074627
],
[
445.3432835820895,
213.43283582089552
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
445.3432835820895,
210.44776119402985
],
[
482.6567164179104,
1013.4328358208954
],
[
428.9253731343283,
1007.4626865671642
],
[
397.5820895522388,
219.40298507462686
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
396.08955223880594,
219.40298507462686
],
[
430.4179104477612,
1011.9402985074627
],
[
312.5074626865671,
1013.4328358208954
],
[
276.6865671641791,
225.3731343283582
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
273.70149253731336,
225.3731343283582
],
[
314.0,
1013.4328358208954
],
[
263.25373134328356,
1014.9253731343283
],
[
222.95522388059703,
222.38805970149252
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "r",
"points": [
[
221.46268656716416,
220.89552238805967
],
[
261.7611940298507,
1016.4179104477612
],
[
245.3432835820895,
1016.4179104477612
],
[
203.5522388059701,
220.89552238805967
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "d",
"points": [
[
591.6119402985074,
195.52238805970148
],
[
202.05970149253733,
223.88059701492537
],
[
208.0298507462686,
289.5522388059701
],
[
590.1194029850745,
249.2537313432836
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "p",
"points": [
[
590.1194029850745,
249.25373134328356
],
[
208.0298507462686,
292.5373134328358
],
[
218.47761194029852,
553.7313432835821
],
[
600.5671641791045,
528.3582089552239
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "i",
"points": [
[
606.5373134328357,
546.2686567164179
],
[
219.97014925373128,
574.6268656716418
],
[
227.43283582089543,
676.1194029850745
],
[
609.5223880597015,
647.7611940298507
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "d",
"points": [
[
609.5223880597015,
677.6119402985074
],
[
227.43283582089543,
705.9701492537313
],
[
231.91044776119395,
802.9850746268656
],
[
616.9850746268656,
774.6268656716418
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "credit",
"points": [
[
618.4776119402984,
789.5522388059701
],
[
230.4179104477612,
814.9253731343283
],
[
240.86567164179098,
937.3134328358209
],
[
622.9552238805969,
913.4328358208954
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
},
{
"label": "b",
"points": [
[
625.9402985074627,
925.3731343283581
],
[
243.85074626865674,
950.7462686567163
],
[
249.820895522388,
1043.2835820895523
],
[
630.4179104477612,
1020.8955223880596
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}
],
"imagePath": "3386991260N_document_three.jpeg",
"imageData": "B8PrZATTfNMw69loEf/2Q==",
"imageHeight": 1280,
"imageWidth": 720
}

Read json file error

I had an issue reading the JSON file. I think it isn't a good idea to use lists to read each lines in this case.
Therefore I changed the code and I suggest you to prefer dictionary research to retrieve the points (also it is less expensive because it is not necessary to read the picture).

In my case, I use rectangle bounding boxes and just one detection class :

with open(txt_path) as json_file:
        data = json.load(json_file)

        w = data["imageWidth"]
        h = data["imageHeight"]

        for idx, shapes in enumerate(data["shapes"]):
            x1 = shapes["points"][0][0]
            y1 = shapes["points"][0][1]
            x2 = shapes["points"][1][0]
            y2 = shapes["points"][1][1]

            cls = str(0) # just one class in my object detection project

            xmin = min(x1, x2)
            xmax = max(x1, x2)
            ymin = min(y1, y2)
            ymax = max(y1, y2)


            b = (xmin, xmax, ymin, ymax)
            bb = convert((w, h), b)

            txt_outfile.write(cls + " " + " ".join([str(a) for a in bb]) + '\n')

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.