一、Labelme制作数据集
- 打开labelme,标注数据,生成文件目录如下:
- data
- a.jpg
- a.json
- b.jpg
- b.json
- …
- data
二、将labelme格式的数据转换为coco格式(转换后的coco格式还是json文件)
-
修改:
-
找到78行
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
-
创建labels.txt(与data文件夹在同一个文件目录中)
- data
- a.jpg
- a.json
- b.jpg
- b.json
- …
- labels.txt
labels.txt内容:
```dotnetcli __ignore__ class 0 class 1 .... ```
- data
-
-
开始转换json格式
python labelme2coco.py ..path/data ..path/data_dataset_coco --labels labels.txt
三、将coco格式转换为YOLO格式
-
文件下载:COCO2YOLO
-
修改
- 修改1:找到 306 行
## with open((fn / f).with_suffix('.txt'), 'a') as file: with open((fn / f[11:]).with_suffix('.txt'), 'a') as file:
- 修改2:找到主函数:修改json路径为你的文件路径
if source == 'COCO': convert_coco_json('..path/data_dataset_coco', # directory with *.json use_segments=True, cls91to80=True)
- 修改1:找到 306 行
-
开始转换json格式
python general_json2yolo.py
-
生成的yolo标注文件在:./new_dir/labels/annotations/