YOLO segmentation data set production
1. Labelme production data set
- Open labelme, label the data, and generate the file directory as follows:
- data
- a.jpg
- a.json
- b.jpg
- b.json
- …
- data
2. Convert the data in labelme format to coco format (the converted coco format is still a json file)
-
Code download: instance_segmentation
-
Revise:
-
78 lines found
class_name_to_id = {} for i, line in enumerate(open(args.labels).readlines()): # class_id = i-1 # starts with -1 class_id = i ## 没有背景,所以索引地址从0开始 class_name = line.strip() if class_id == -1: assert class_name == "__ignore__" continue
-
Create labels.txt (in the same file directory as the data folder)
- data
- a.jpg
- a.json
- b.jpg
- b.json
- …
- labels.txt
labels.txt content:
```dotnetcli __ignore__ class 0 class 1 .... ```
- data
-
-
Start converting json format
python labelme2coco.py ..path/data ..path/data_dataset_coco --labels labels.txt
3. Convert coco format to YOLO format
-
File download: COCO2YOLO
-
Revise
- Modification 1: Find 306 lines
## with open((fn / f).with_suffix('.txt'), 'a') as file: with open((fn / f[11:]).with_suffix('.txt'), 'a') as file:
- Modification 2: Find the main function: modify the json path to your file path
if source == 'COCO': convert_coco_json('..path/data_dataset_coco', # directory with *.json use_segments=True, cls91to80=True)
- Modification 1: Find 306 lines
-
Start converting json format
python general_json2yolo.py
-
The generated yolo annotation file is in: ./new_dir/labels/annotations/