赞
踩
当前目标检测领域常用的数据集格式非 COCO、VOC、YOLO莫属,但是很多算法的源码或者框架只支持一种数据格式,数据集格式不匹配的时候就需要自己手动进行转换。
因此我最近整理了一下这三种格式互相转化的代码,并且添加了标签可视化的代码,以后打比赛或者其他情况下能节省部分手动转换的时间。
代码github地址:https://github.com/FireworksFallDown/TypeTotype.git
对于windows用户,我还提供了相应的exe程序,可以直接在图形界面进行操作。
如果github登不上去的话推荐在 码云gitee里创建仓库直接导入github地址,就能够轻松下载了
Annotations.json -------------------------------------------------------------------------------------------------- { "images": [ { "file_name": "***.jpg", # string "height": ***, # int "width": ***, # int "id": * # int },...] "annotations": [ { "iscrowd": 0, # 0 or 1 "area": *, # float or double "image_id": 0, # int "bbox": [*, *, *, *], # list[float], [x,y,w,h] "category_id": *, # int "id": * # int },...] "categories": [ {"id": *, "name": "***"}, # id start from 1 ... ] }
VOC type: Annotations |—— ImgName_1.xml |—— ImgName_2.xml ... -------------------------------------------------------------------------------------------------- ImgName_1.xml : -------------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <annotation> <folder>VOC2007</folder> <filename>***.jpeg</filename> <size> <width>***</width> <height>***</height> <depth>3</depth> </size> <object> <name>***</name> # category name <bndbox> <xmin>*</xmin> <xmax>*</xmax> <ymin>*</ymin> <ymax>*</ymax> </bndbox> <truncated>0</truncated> <difficult>0</difficult> </object> ... <segmented>0</segmented> </annotation>
imgName_1.txt:
--------------------------------------------------------------------------------------------------
cateId center_x center_y w h # normalization type, eg: 0 0.473667 0.397000 0.116000 0.337000
...
--------------------------------------------------------------------------------------------------
其实挺简单的,就是各个格式的文件读取稍显麻烦,这里不做详细介绍,我直接放在github上了,可以直接使用
其中读取coco格式标注是使用json包,VOC是使用xml.etree.ElementTree的相关api
详情可以见源码
代码目前支持VOC,COCO,YOLO这三种任意两种之间的转换(不包含分割信息,仅支持目标检测标注,同时也不包含困难样本等等信息的转换),以及这三种标签的可视化。
support mode:
使用:
需要保证环境中已安装 opencv-python, numpy, xml, json等包
下载源码后,
① 需要在my_config.py中修改类别名称为你的数据集类别名称
② 在 Type2Type 目录下使用下面的命令行进行转换或者可视化
python main.py --img_path [your path] --mode [your mode] --label_path [your label path] --save_path [your save path]
注意事项
① 运行 python main.py --help
可以查看提示信息
② mode 选项必须是下面各模式中的一个
VOC2COCO, VOC2YOLO, YOLO2COCO, YOLO2VOC, COCO2YOLO, COCO2VOC,LabelView_COCO, LabelView_VOC, LabelView_YOLO
③ 如果只是标签可视化的话可以忽略 --save_path
选项
④ 我还提供了windows下的exe程序,可以直接运行目录下的Type2Type.exe,然后直接在图形界面进行操作
⑤ 文件目录最好保证为全英文路径,否则可能会无法读取导致运行失败
⑥ 可能会存在部分bug, 如果使用过程中发现还请反馈,我会尽快进行优化
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。