python脚本自动使用labelme标注数据集

PYTHON 十一月 06, 2019

python脚本自动使用labelme标注数据集

文章字数 4.7k 阅读约需 4 mins. 阅读次数 1000000

使用工具:labelme(标注mask数据集用的)

GitHub地址: https://github.com/wkentaro/labelme
windows:
python2

1
2
pip install pyqt
pip install labelme

python3

1
2
pip install pyqt5
pip install labelme

Ubuntu16.04系统下采用自带的python2.7环境:

1
2
sudo apt-get install python-qt4 pyqt4-dev-tools 
sudo pip install labelme *# python2 works*

使用

在终端中进入labelme.exe所在文件夹,执行命令:

1
labelme

出现界面后,点击open, 打开需要标注的图像,选择对目标区域进行标注
标注完后点击会产生json文件

python自动图像语义分割标注脚本:

引入os库实现python在命令行中执行命令:

1
import os

定义获取之前制作的全部json文件的文件名的函数

1
2
3
4
5
6
7
8
9
def getAllJson(path):
"""获取所有json文件名\n
path : 文件夹路径字符串"""
dirs = os.listdir(path)
dirList = []
for d in dirs :
if os.path.splitext(d)[1] == ".json" :
dirList.append(d)
return dirList

定义生成语义分割文件的函数,命令行中的命令格式为”labelme_json_to_dataset 文件名“:

1
2
3
4
5
6
def generate(fileList) :
"""生成数据集图像\n
list : 文件名列表"""
for f in fileList :
s = "labelme_json_to_dataset " + "F:/ISIC/ISIC-images/json/" + f
os.system(s)

执行函数:

1
2
fileList = getAllJson("F:/ISIC/ISIC-images/json")
generate(fileList)
0%