COCO json annotation to YOLO txt format

Viewed 6551

enter image description here

how to convert a single COCO JSON annotation file into a YOLO darknet format?? like below each individual image has separate filename.txt file enter image description here

3 Answers

I built a tool https://github.com/tw-yshuang/coco2yolo

Download this repo and use the following command:

python3 coco2yolo.py [OPTIONS]

coc2yolo

Usage: coco2yolo.py [OPTIONS] [CAT_INFOS]...

Options:
  -ann-path, --annotations-path TEXT
                                  JSON file. Path for label.  [required]
  -img-dir, --image-download-dir TEXT
                                  The directory of the image data place.
  -task-dir, --task-categories-dir TEXT
                                  Build a directory that follows the task-required categories.
  -cat-t, --category-type TEXT    Category input type. (interactive | file)  [default: interactive]
  -set, --set-computing-type TEXT
                                  Set Computing for the data. (union | intersection)  [default: union]
  --help                          Show this message and exit.

My classmates and I have created a python package called PyLabel to help others with this task and other labelling tasks.

Our package does this conversion! You can see an example in this notebook https://github.com/pylabel-project/samples/blob/main/coco2yolov5.ipynb.

You're answer should be in there! But you should be able to do this conversion by doing something like:

!pip install pylabel
from pylabel import importer
dataset = importer.ImportCoco(path=path_to_annotations, path_to_images=path_to_images)
dataset.export.ExportToYoloV5(dataset)

You can find the source code that is used behind the scenes here https://github.com/pylabel-project/

There is an open-source tool called makesense.ai for annotating your images. You can download YOLO txt format once you annotate your images. But you won't be able to download the annotated images.

Related