The txt annotation file of Yolo v5 is converted into a json annotation file in coco format

There are many articles in the community that convert json annotation files in coco dataset format to yolo txt format, but bloggers have not found how to convert txt to json. This article will provide you with a very convenient small script to achieve this function.

It should be noted that if it is more troublesome to directly convert the annotation file in txt format to the annotation file in json format, it can be done in two steps:

  • Step 1: Convert txt format annotations to xml format annotations.
  • Step 2: Convert xml format annotations to json format annotations.

The script file of the first step is as follows, you only need to modify the three parameters in the yolo2voc() method: the image storage directory, the txt format label storage directory, and the directory where the classes.txt file is located. The contents of the classes.txt file are as follows, with the class names in order:

Then run the script to create a folder in the current root directory and generate xml format annotations.

Guess you like

Origin blog.csdn.net/qq_42308217/article/details/123547150