labelme使用教程
0. 安装
pip install labelme
1. 运行
demo
labelme img_dir --nodata --autosave --output output_dir
运行上面的命令会弹出labelme的标注界面,标注完成之后会在output_dir
目录下生成json文件,生成的文件如下.
其中的一些key的含义:
- label:类别名称
- points:[[x1,y1],[x2,y2],…] 图像左上角为坐标原点
- shape_type
- rectangle:矩形框标注
- polygon:多边形框标注
{
"version": "5.0.1",
"flags": {},
"shapes": [
{
"label": "window",
"points": [
[
618.8,
279.2
],
[
1278.0,
716.8
]
],
"group_id": null,
"shape_type": "rectangle",
"flags": {}
},
{
"label": "window",
"points": [
[
678.8,
347.2
],
[
707.6,
700.8
],
[
1266.0,
652.0
],
[
1205.2,
288.0
]
],
"group_id": null,
"shape_type": "polygon",
"flags": {}
}
],
"imagePath": "0.jpg",
"imageData": null,
"imageHeight": 720,
"imageWidth": 1280
}
标注视频
需要先将视频帧转换成图像帧,然后运行下面的命令对生成的图像文件夹进行标注
labelme img_dir --nodata --keep-prev --autosave -o output_dir
其中--keep-prev
参数会将上一帧的标注保存到当前帧
labelme D:\DataSet\img\left_fish --nodata --keep-prev --autosave -o D:\DataSet\img\left_fish_label
语义分割
./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt
其中,
labelme2voc
是官方的转换文件- 你
data_annotated
是你标注得到的json
文件路径data_dataset_voc
是输出的文件目录label.txt
是标注信息
data_dataset_voc
的目录结构如下:
data_dataset_voc
├── JPEGImages
├── SegmentationClass
├── SegmentationClassVisualization
2. 命令行参数
positional arguments:
filename image or label filename
optional arguments:
-h, --help show this help message and exit
--version, -V show version
--reset-config reset qt config
--logger-level {debug,info,warning,fatal,error}
logger level
--output OUTPUT, -O OUTPUT, -o OUTPUT
output file or directory (if it ends with .json it is recognized as file, else as directory)
--config CONFIG config file or yaml-format string (default: C:\Users\Lenovo\.labelmerc)
--nodata stop storing image data to JSON file
--autosave auto save
--nosortlabels stop sorting labels
--flags FLAGS comma separated list of flags OR file containing flags
--labelflags LABEL_FLAGS
yaml string of label specific flags OR file containing json string of label specific flags
(ex. {person-\d+: [male, tall], dog-\d+: [black, brown, white], .*: [occluded]})
--labels LABELS comma separated list of labels OR file containing labels
--validatelabel {exact}
label validation types
--keep-prev keep annotation of previous frame
--epsilon EPSILON epsilon to find nearest vertex on canvas
3. labelme2voc.py
可以将标注生成的json
文件生成voc格式的语义mask,可以通过运行一下命令来使用。
./labelme2voc.py data_annotated data_dataset_voc --labels labels.txt