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

- 121
- 1
- 2
- 8
4 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.

- 83
- 1
- 5
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/

- 94
- 1
- 2
-
No it's not working, it converting it to YAML, not a txt file ! – MEH Mar 01 '22 at 06:30
-
1@Derek `dataset.export.ExportToYoloV5(dataset)`: shouldn't the argument of `ExportToYoloV5()` method be something line `ExportToYoloV5(output_path='./yolo')` ? – Tangent Jul 09 '22 at 11:21
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.

- 9
- 2
-
This does not address the question. The question is how to convert an existing JSON formatted dataset to YAML format, not how to export a dataset into YAML format. – Georgi Georgiev Jul 21 '23 at 15:54
There is three ways.
- use roboflow https://roboflow.com/formats (You can find another solution also)
You can find some usage guide for roboflow. e.g. https://medium.com/red-buffer/roboflow-d4e8c4b52515
search 'convert coco format to yolo format' -> you will find some open-source codes to convert annotations to yolo format.
write your own code to convert coco format to yolo format

- 157
- 1
- 8
-
2This is one of the methods to convert the file format but the data will be publicised. – DGKang Apr 30 '23 at 17:28