HumanSignal / label-studio-converter

Tools for converting Label Studio annotations into common dataset formats
https://labelstud.io/
255 stars 132 forks source link

feat: YOLO import includes images without label files #173

Closed Mekcyed closed 1 year ago

Mekcyed commented 1 year ago

Hey,

Firstly: thanks for this toolbox which saved me a lot of time.

I noticed with the yolo import function, that it does not include images which do not have a corresponding label file. But when creating predictions/ annotations with yolo it can happen that yolo does not detect anything. In this case no label txt file is created.

I propose a change of the converting loop in yolo.py.

Instead of looping through the folder with the label files it should loop through the image folder. The output for the label-studio json file would now include images without predictions/ annotations:

[      
        {
        "data": {
            "image": "/data/local-files/?d=/folder/image.jpg"
        },
        "predictions": [
            {
                "result": [
                    {
                        "id": "498b1bfa94",
                        "type": "rectanglelabels",
                        "value": {
                            "x": 3.4374700000000007,
                            "y": 0.18516999999999978,
                            "width": 12.9688,
                            "height": 17.963,
                            "rotation": 0,
                            "rectanglelabels": [
                                "person"
                            ]
                        },
                        "to_name": "image",
                        "from_name": "label",
                        "image_rotation": 0,
                        "original_width": 1920,
                        "original_height": 1080
                    },
                    {
                        "id": "d297476aa9",
                        "type": "rectanglelabels",
                        "value": {
                            "x": 0.05205999999999961,
                            "y": 4.537050000000001,
                            "width": 14.218800000000002,
                            "height": 33.4259,
                            "rotation": 0,
                            "rectanglelabels": [
                                "person"
                            ]
                        },
                        "to_name": "image",
                        "from_name": "label",
                        "image_rotation": 0,
                        "original_width": 1920,
                        "original_height": 1080
                    }
                ],
                "ground_truth": false
            }
        ]
    },
    {
        "data": {
            "image": "/data/local-files/?d=/folder/image.jpg"
        }
    }
]
Mekcyed commented 1 year ago

@makseq Could you give some hints on what you would like to see in a yolo test? And are there functions to validate whether a json is valid to be imported to label-studio?

makseq commented 1 year ago

@makseq Could you give some hints on what you would like to see in a yolo test? And are there functions to validate whether a json is valid to be imported to label-studio?

It would be great to see how ls converter takes a folder with yolo images and labeling files and generates the output LS json. So, we can check this generated json with ground truth json that we've prepared beforehand for this test.

makseq commented 1 year ago

please, resolve conflict with master

Mekcyed commented 1 year ago

Failed to merge first and reopened the pr...

I resolved the conflict with pr #156. I noticed that meanwhile the yolo tests were added also. Edit: I will also update them due to the fact, that with looping through the images a different amount of images and labels maybe possible No changes in test_import_yolo.py needed in my opinion. With my change all images are included in the yolo_exp_test.json. Even if one label file is removed from the labels folder.