export-to-yolo

You need to be a Pro member to access the full content of this.

export-to-yolo converts Labelme dataset to YOLO format. It exports the dataset to a directory with the following structure:

What is YOLO format?

The YOLO format consists of two directories: images and labels. The images directory contains the images, and the labels directory contains the label files. Each label file has the same name as the image file but with a .txt extension.

The label file contains the bounding box annotations in the following format:

<class_id> <center_x> <center_y> <width> <height>

where:

NOTE: If you provide non-rectangle annotations such as polygons or masks, the tool will compute the bounding box for each annotation.

Usage

Pass either a JSON file or directory of JSON files.

labelmetk export-to-yolo [OPTIONS] DATASET_DIR

Options:

--class-names: Required. Specify class names as a comma-separated text (e.g., --class-names cat,dog). Use labelmetk list-labels to list the labels in a dataset.

Example: Export a Dataset

Pass the directory containing the JSON files and the class names to export the dataset to YOLO format.

$ labelmetk export-to-yolo small_dataset/ --class-names bottle,bus,car,chair,person,sofa
Found 3 JSON files: ['small_dataset/2011_000003.json', 'small_dataset/2011_000025.json', 'small_dataset/2011_000006.json']
warning: [small_dataset/2011_000003.json] shapes[0].label='__ignore__' is not in class_names. skipping
warning: [small_dataset/2011_000006.json] shapes[0].label='__ignore__' is not in class_names. skipping
[small_dataset/] Exported to small_dataset.export

The exported directory will have the following structure:

small_dataset.export
├── classes.txt
├── images
│   ├── 2011_000003.jpg
│   ├── 2011_000006.jpg
│   └── 2011_000025.jpg
└── labels
    ├── 2011_000003.txt
    ├── 2011_000006.txt
    └── 2011_000025.txt

You can list the labels in a dataset using labelmetk list-labels command.

$ labelmetk list-labels small_dataset/
__ignore__
bottle
bus
car
chair
person
sofa

Download an example dataset from:

small_dataset.zip (389KB)