ultralytics / JSON2YOLO

Convert JSON annotations into YOLO format.
https://docs.ultralytics.com
GNU Affero General Public License v3.0
808 stars 228 forks source link

How do I use this script? #1

Open ivanquirino opened 5 years ago

ivanquirino commented 5 years ago

I have a coco.json file but when I run this script I've got the following error:

Traceback (most recent call last):
  File "./run.py", line 88, in <module>
    main(name, file)
  File "./run.py", line 60, in main
    with open('out/labels/' + label_name, 'a') as file:
FileNotFoundError: [Errno 2] No such file or directory: 'out/labels/IMG_https://storage.googleapis.com/labelbox-193903.appspot.com/cjvzre25678v10804t8epwim4%2F501af721-032d-33d3-e4b5-cc584ff45244-769a3159-1ecf-4f3e-aa8f-e09f0bde6014_LA.txt'
glenn-jocher commented 5 years ago

@ivanquirino this script can be used to import JSON files from other formats into the YOLO format used for training darknet or ultralytics/yolov3.

getcontrol commented 4 years ago

What is the EXACT command to execute this script?

I enter in terminal:

python run.py export-2019-11-18T18_30_26.769Z.json

also try simply

python run.py

Output =

Files and Shapes: 0it [00:00, ?it/s]
Annotations: 0it [00:00, ?it/s]
Done. Output saved to /Users/getcontrol/projects/JSON2YOLO/../out/`

All of the files and directories in out/ are empty. Screenshot 2019-11-18 11 06 13

glenn-jocher commented 4 years ago

@ivanquirino you can modify this section to specify labelbox format and to point to your labelbox json:

https://github.com/ultralytics/JSON2YOLO/blob/898f174547b6485d132fa903427d316f33e9d721/run.py#L302-L308

daddydrac commented 4 years ago

Same issue with this one, lack of docs. I have COCO annotations in JSON format and not sure which one I can use to format 'COCO JSON' into 'Darknet .txt format'.

daddydrac commented 4 years ago

For example, my COCO JSON Annotations look like this, in which I have a unique JSON file for every image:

{
    "annotation": [
        {
            "area": 7350,
            "bbox": [
                396,
                200,
                147,
                50
            ],
            "category_id": "3",
            "id": 1,
            "image_id": 2,
            "iscrowd": 0,
            "segmentation": [
                [
                    396,
                    200,
                    396,
                    250,
                    543,
                    250,
                    543,
                    200
                ]
            ]
        } 
]

I need to know how to use the run.py file to make .txt files for Darknet, that look like this:

3 0.497327 0.511852 0.948637 0.952609 
3 0.240637 0.217617 0.475398 0.424859 

Is this even supported in this tool? I ask because when I print out the variable 'x' in run.py from line 148-150, I get:

{'annotation': [], 'image': {'file_name': 'FLIR_01538', 'height': 512, 'id': 1538, 'width': 640}, ...'}

Based on the code from line 151-ish, it looks like 'x' expects: x['asset']['name'] + '.jpg')

glenn-jocher commented 4 years ago

@joehoeller the repo only offers export from a limited number of JSON labelling providers below. Since each JSON format is different, we have to write custom functions for each format. We don't have a COCO JSON export function yet.

daddydrac commented 4 years ago

Can you add me to the project so I can contrib the following:

  1. COCO JSON -> Darknet/YOLO .txt format
  2. Write new or re-write better tutorials/docs
  3. Composable metrics for any CNN arch used

On Wed, Nov 27, 2019 at 1:16 PM Glenn Jocher notifications@github.com wrote:

@joehoeller https://github.com/joehoeller the repo only offers export from a limited number of JSON labelling providers below. Since each JSON format is different, we have to write custom functions for each format. We don't have a COCO JSON export function yet.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ultralytics/JSON2YOLO/issues/1?email_source=notifications&email_token=ABHVQHCWSISHHFP5S5RPN2TQV3BQBA5CNFSM4HOYP4Z2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFKP45A#issuecomment-559218292, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHVQHAA66E6PVRYJDT3KRDQV3BQBANCNFSM4HOYP4ZQ .

glenn-jocher commented 4 years ago

@joehoeller may try this script: https://github.com/AlexeyAB/darknet/issues/3772#issuecomment-559242998

Yeah I can add you on. I forgot how to do that! Let me check.

daddydrac commented 4 years ago

@glenn-jocher I guess no one had a working script that would automate COCO JSON -> Darknet. I made one :) let me know when I’m added to repo and I’ll post as pull request.

SteelMinh commented 4 years ago

@joehoeller can you show me your script that convert the JSON to Darknet?

daddydrac commented 4 years ago

@joehoeller can you show me your script that convert the JSON to Darknet?

It may have some bugs, so let me know, and I'll fix. Its basically a version 0.5 right now: COCO JSON to Darknet/Yolo annotation conversion: https://github.com/joehoeller/Dark-Chocolate,

daddydrac commented 4 years ago

@joehoeller may try this script: AlexeyAB/darknet#3772 (comment)

Yeah I can add you on. I forgot how to do that! Let me check.

not added yet

Hamid-Najafi commented 4 years ago

finally, How to use this with VoTT JSON ? is there any instruction ?

duyao-art commented 4 years ago

@glenn-jocher Hello! Thank you for your advice recently.

I have a question. Now I want to retrain the yolov3 based on my built dateset. I am wondering if there are some requirements about the image size? Should the image data has the same size? Does the same size will make the train and detection accuracy better? I know in your Yolo project, there are several codes to transform the input image size to the standard 416*416 or other unit 32 image size. I just wonder if it is needed to revise the size of my collected image size, because the sizes are different. Also, if it is also necessary that the image format must be .jpg format, can not be .png or other format?

I would be appreciated if you could reply to me in your free time.

glenn-jocher commented 4 years ago

@duyao-art @Goldenstarc these are mostly internal tools we use for some client conversions that we've uploaded to github for version control purposes, hence the lack of documentation. If they work for you, great, but we do not have resources to help you at the moment.

duyao-art commented 4 years ago

@glenn-jocher OK. Thank you again for your kind reply.

Hamid-Najafi commented 4 years ago

It’s a perfect tool. I wish you publish its instructions manual publicly.

khandriod commented 2 years ago

@Hamid-Najafi how did you use this tool? Could you please help me with it get started?

glenn-jocher commented 10 months ago

@Hamid-Najafi thanks for your interest! Feel free to ask any specific questions you may have about using the tool. I'm here to help!

Mary14-design commented 5 months ago

Coco dataset contains multiple json files, not only one. How to convert each one?

glenn-jocher commented 5 months ago

@Mary14-design hello! 😊 To convert multiple COCO JSON files to the format expected by our tool, you can use a simple loop in your script. Here's a basic example:

import os

json_files = ['path/to/your/first.json', 'path/to/your/second.json']  # Add your JSON file paths here
for json_file in json_files:
    # Your conversion function here, e.g.,
    convert_coco_json(json_file, output_dir='desired/output/path')

Just replace convert_coco_json with the actual function you're using for conversion, and ensure json_files contains the paths to all your COCO JSON files. This way, each file will be processed in turn. If you have any further questions, feel free to ask! 🚀

DishantMewada commented 3 months ago

Step 1: First install requirements with pip install -r requirements.txt Step 2: I placed my json files in "data" folder and changed the "general_json2yolo.py" as follows


if __name__ == "__main__":
    source = "COCO"

    if source == "COCO":
        convert_coco_json(
            "./data/",  # directory with *.json
            use_segments=False,
            cls91to80=True,
        )

Step 3: run it with "python general_json2yolo.py" It will create new_dir/labels/name_of_the_json_file/*.txt