Dataset Conversion
The folder tools/data_converters
currently contains ballon2coco.py
, yolo2coco.py
, and labelme2coco.py
- three dataset conversion tools.
ballon2coco.py
converts theballoon
dataset (this small dataset is for starters only) to COCO format.
python tools/dataset_converters/balloon2coco.py
yolo2coco.py
converts a dataset fromyolo-style
.txt format to COCO format, please use it as follows:
python tools/dataset_converters/yolo2coco.py /path/to/the/root/dir/of/your_dataset
Instructions:
image_dir
is the root directory of the yolo-style dataset you need to pass to the script, which should containimages
,labels
, andclasses.txt
.classes.txt
is the class declaration corresponding to the current dataset. One class a line. The structure of the root directory should be formatted as this example shows:
.
βββ $ROOT_PATH
βββ classes.txt
βββ labels
β βββ a.txt
β βββ b.txt
β βββ ...
βββ images
β βββ a.jpg
β βββ b.png
β βββ ...
βββ ...
- The script will automatically check if
train.txt
,val.txt
, andtest.txt
have already existed underimage_dir
. If these files are located, the script will organize the dataset accordingly. Otherwise, the script will convert the dataset into one file. The image paths in these files must be ABSOLUTE paths. - By default, the script will create a folder called
annotations
in theimage_dir
directory which stores the converted JSON file. Iftrain.txt
,val.txt
, andtest.txt
are not found, the output file isresult.json
. Otherwise, the corresponding JSON file will be generated, named astrain.json
,val.json
, andtest.json
. Theannotations
folder may look similar to this:
.
βββ $ROOT_PATH
βββ annotations
β βββ result.json
β βββ ...
βββ classes.txt
βββ labels
β βββ a.txt
β βββ b.txt
β βββ ...
βββ images
β βββ a.jpg
β βββ b.png
β βββ ...
βββ ...