labelme如何标注此处不做介绍,另外,此脚本也可以用于语义分割数据集转换为实例分割格式,只需要将语义分割的mask标签图先转换为json格式即可,转换方式参考上篇博客。
一、下载labelme源码
git clone https://github.com/wkentaro/labelme
在刚标记好的图片数据文件夹外,新建一个label.txt
,必须包含__ignore__, _background_
位置如下所示:
其中:
img-and-jsons:存放图片和labelme标好的json文件
labelme-main:github下载的源码
out:输出路径
二、转为语义分割
进入labelme-main\examples\semantic_segmentation
文件夹,有支持转换VOC 格式的代码
将labelme2voc.py拷贝至img-and-jsons同目录下,运行:
python labelme2voc.py img-and-jsons out_voc --labels label.txt
会在out_voc下生成对应文件:
此时:SegmentationClass下的png标签文件为全黑图,标签值非常低(例如 0、4、14)
,可以通过以下方式查看标签 png 文件:
labelme_draw_label_png data_dataset_voc/SegmentationClassPNG/2011_000003.png
三、转为实例分割
进入labelme-main\examples\instance_segmentation
文件夹,有支持转换COCO 及VOC 格式的代码:
将labelme2coco.py拷贝至img-and-jsons同目录下,运行:
python labelme2coco.py img-and-jsons out_coco --labels label.txt
会在out_coco下生成对应文件:
JPEGImages
是原本的图片,Visualization
是框起来的图片,annotations.json
是标记好的label