Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不会修仙的道士
labelme
提交
612b40df
L
labelme
项目概览
不会修仙的道士
/
labelme
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
labelme
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
612b40df
编写于
1月 26, 2020
作者:
K
Kentaro Wada
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update labelme2voc.py and labelme2coco.py accordingly
上级
9a191df9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
43 addition
and
33 deletion
+43
-33
examples/instance_segmentation/labelme2coco.py
examples/instance_segmentation/labelme2coco.py
+16
-8
examples/instance_segmentation/labelme2voc.py
examples/instance_segmentation/labelme2voc.py
+0
-1
examples/semantic_segmentation/labelme2voc.py
examples/semantic_segmentation/labelme2voc.py
+1
-1
labelme/cli/draw_json.py
labelme/cli/draw_json.py
+3
-1
labelme/cli/json_to_dataset.py
labelme/cli/json_to_dataset.py
+3
-1
labelme/utils/shape.py
labelme/utils/shape.py
+18
-19
tests/labelme_tests/utils_tests/test_shape.py
tests/labelme_tests/utils_tests/test_shape.py
+1
-1
tests/labelme_tests/utils_tests/util.py
tests/labelme_tests/utils_tests/util.py
+1
-1
未找到文件。
examples/instance_segmentation/labelme2coco.py
浏览文件 @
612b40df
...
@@ -8,6 +8,7 @@ import json
...
@@ -8,6 +8,7 @@ import json
import
os
import
os
import
os.path
as
osp
import
os.path
as
osp
import
sys
import
sys
import
uuid
import
numpy
as
np
import
numpy
as
np
import
PIL.Image
import
PIL.Image
...
@@ -111,21 +112,28 @@ def main():
...
@@ -111,21 +112,28 @@ def main():
for
shape
in
label_data
[
'shapes'
]:
for
shape
in
label_data
[
'shapes'
]:
points
=
shape
[
'points'
]
points
=
shape
[
'points'
]
label
=
shape
[
'label'
]
label
=
shape
[
'label'
]
shape_type
=
shape
.
get
(
'shape_type'
,
None
)
group_id
=
shape
.
get
(
'group_id'
)
shape_type
=
shape
.
get
(
'shape_type'
)
mask
=
labelme
.
utils
.
shape_to_mask
(
mask
=
labelme
.
utils
.
shape_to_mask
(
img
.
shape
[:
2
],
points
,
shape_type
img
.
shape
[:
2
],
points
,
shape_type
)
)
if
label
in
masks
:
if
group_id
is
None
:
masks
[
label
]
=
masks
[
label
]
|
mask
group_id
=
uuid
.
uuid1
()
instance
=
(
label
,
group_id
)
if
instance
in
masks
:
masks
[
instance
]
=
masks
[
instance
]
|
mask
else
:
else
:
masks
[
label
]
=
mask
masks
[
instance
]
=
mask
points
=
np
.
asarray
(
points
).
flatten
().
tolist
()
points
=
np
.
asarray
(
points
).
flatten
().
tolist
()
segmentations
[
label
].
append
(
points
)
segmentations
[
instance
].
append
(
points
)
segmentations
=
dict
(
segmentations
)
for
label
,
mask
in
masks
.
items
():
for
instance
,
mask
in
masks
.
items
():
cls_name
=
label
.
split
(
'-'
)[
0
]
cls_name
,
group_id
=
instance
if
cls_name
not
in
class_name_to_id
:
if
cls_name
not
in
class_name_to_id
:
continue
continue
cls_id
=
class_name_to_id
[
cls_name
]
cls_id
=
class_name_to_id
[
cls_name
]
...
@@ -139,7 +147,7 @@ def main():
...
@@ -139,7 +147,7 @@ def main():
id
=
len
(
data
[
'annotations'
]),
id
=
len
(
data
[
'annotations'
]),
image_id
=
image_id
,
image_id
=
image_id
,
category_id
=
cls_id
,
category_id
=
cls_id
,
segmentation
=
segmentations
[
label
],
segmentation
=
segmentations
[
instance
],
area
=
area
,
area
=
area
,
bbox
=
bbox
,
bbox
=
bbox
,
iscrowd
=
0
,
iscrowd
=
0
,
...
...
examples/instance_segmentation/labelme2voc.py
浏览文件 @
612b40df
...
@@ -103,7 +103,6 @@ def main():
...
@@ -103,7 +103,6 @@ def main():
img_shape
=
img
.
shape
,
img_shape
=
img
.
shape
,
shapes
=
data
[
'shapes'
],
shapes
=
data
[
'shapes'
],
label_name_to_value
=
class_name_to_id
,
label_name_to_value
=
class_name_to_id
,
type
=
'instance'
,
)
)
ins
[
cls
==
-
1
]
=
0
# ignore it.
ins
[
cls
==
-
1
]
=
0
# ignore it.
...
...
examples/semantic_segmentation/labelme2voc.py
浏览文件 @
612b40df
...
@@ -81,7 +81,7 @@ def main():
...
@@ -81,7 +81,7 @@ def main():
f
.
write
(
label_file
.
imageData
)
f
.
write
(
label_file
.
imageData
)
img
=
labelme
.
utils
.
img_data_to_arr
(
label_file
.
imageData
)
img
=
labelme
.
utils
.
img_data_to_arr
(
label_file
.
imageData
)
lbl
=
labelme
.
utils
.
shapes_to_label
(
lbl
,
_
=
labelme
.
utils
.
shapes_to_label
(
img_shape
=
img
.
shape
,
img_shape
=
img
.
shape
,
shapes
=
label_file
.
shapes
,
shapes
=
label_file
.
shapes
,
label_name_to_value
=
class_name_to_id
,
label_name_to_value
=
class_name_to_id
,
...
...
labelme/cli/draw_json.py
浏览文件 @
612b40df
...
@@ -41,7 +41,9 @@ def main():
...
@@ -41,7 +41,9 @@ def main():
else
:
else
:
label_value
=
len
(
label_name_to_value
)
label_value
=
len
(
label_name_to_value
)
label_name_to_value
[
label_name
]
=
label_value
label_name_to_value
[
label_name
]
=
label_value
lbl
=
utils
.
shapes_to_label
(
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
lbl
,
_
=
utils
.
shapes_to_label
(
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
label_names
=
[
None
]
*
(
max
(
label_name_to_value
.
values
())
+
1
)
label_names
=
[
None
]
*
(
max
(
label_name_to_value
.
values
())
+
1
)
for
name
,
value
in
label_name_to_value
.
items
():
for
name
,
value
in
label_name_to_value
.
items
():
...
...
labelme/cli/json_to_dataset.py
浏览文件 @
612b40df
...
@@ -50,7 +50,9 @@ def main():
...
@@ -50,7 +50,9 @@ def main():
else
:
else
:
label_value
=
len
(
label_name_to_value
)
label_value
=
len
(
label_name_to_value
)
label_name_to_value
[
label_name
]
=
label_value
label_name_to_value
[
label_name
]
=
label_value
lbl
=
utils
.
shapes_to_label
(
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
lbl
,
_
=
utils
.
shapes_to_label
(
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
label_names
=
[
None
]
*
(
max
(
label_name_to_value
.
values
())
+
1
)
label_names
=
[
None
]
*
(
max
(
label_name_to_value
.
values
())
+
1
)
for
name
,
value
in
label_name_to_value
.
items
():
for
name
,
value
in
label_name_to_value
.
items
():
...
...
labelme/utils/shape.py
浏览文件 @
612b40df
import
math
import
math
import
uuid
import
numpy
as
np
import
numpy
as
np
import
PIL.Image
import
PIL.Image
...
@@ -46,33 +47,31 @@ def shape_to_mask(img_shape, points, shape_type=None,
...
@@ -46,33 +47,31 @@ def shape_to_mask(img_shape, points, shape_type=None,
return
mask
return
mask
def
shapes_to_label
(
img_shape
,
shapes
,
label_name_to_value
,
type
=
'class'
):
def
shapes_to_label
(
img_shape
,
shapes
,
label_name_to_value
):
assert
type
in
[
'class'
,
'instance'
]
cls
=
np
.
zeros
(
img_shape
[:
2
],
dtype
=
np
.
int32
)
cls
=
np
.
zeros
(
img_shape
[:
2
],
dtype
=
np
.
int32
)
if
type
==
'instance'
:
ins
=
np
.
zeros_like
(
cls
)
ins
=
np
.
zeros
(
img_shape
[:
2
],
dtype
=
np
.
int32
)
instances
=
[]
instance_names
=
[
'_background_'
]
for
shape
in
shapes
:
for
shape
in
shapes
:
points
=
shape
[
'points'
]
points
=
shape
[
'points'
]
label
=
shape
[
'label'
]
label
=
shape
[
'label'
]
group_id
=
shape
.
get
(
'group_id'
)
if
group_id
is
None
:
group_id
=
uuid
.
uuid1
()
shape_type
=
shape
.
get
(
'shape_type'
,
None
)
shape_type
=
shape
.
get
(
'shape_type'
,
None
)
if
type
==
'class'
:
cls_name
=
label
cls_name
=
label
elif
type
==
'instance'
:
instance
=
(
cls_name
,
group_id
)
cls_name
=
label
.
split
(
'-'
)[
0
]
if
label
not
in
instance_nam
es
:
if
instance
not
in
instanc
es
:
instance_names
.
append
(
label
)
instances
.
append
(
instance
)
ins_id
=
instance_names
.
index
(
label
)
ins_id
=
instances
.
index
(
instance
)
+
1
cls_id
=
label_name_to_value
[
cls_name
]
cls_id
=
label_name_to_value
[
cls_name
]
mask
=
shape_to_mask
(
img_shape
[:
2
],
points
,
shape_type
)
mask
=
shape_to_mask
(
img_shape
[:
2
],
points
,
shape_type
)
cls
[
mask
]
=
cls_id
cls
[
mask
]
=
cls_id
if
type
==
'instance'
:
ins
[
mask
]
=
ins_id
ins
[
mask
]
=
ins_id
if
type
==
'instance'
:
return
cls
,
ins
return
cls
,
ins
return
cls
def
labelme_shapes_to_label
(
img_shape
,
shapes
):
def
labelme_shapes_to_label
(
img_shape
,
shapes
):
...
@@ -88,7 +87,7 @@ def labelme_shapes_to_label(img_shape, shapes):
...
@@ -88,7 +87,7 @@ def labelme_shapes_to_label(img_shape, shapes):
label_value
=
len
(
label_name_to_value
)
label_value
=
len
(
label_name_to_value
)
label_name_to_value
[
label_name
]
=
label_value
label_name_to_value
[
label_name
]
=
label_value
lbl
=
shapes_to_label
(
img_shape
,
shapes
,
label_name_to_value
)
lbl
,
_
=
shapes_to_label
(
img_shape
,
shapes
,
label_name_to_value
)
return
lbl
,
label_name_to_value
return
lbl
,
label_name_to_value
...
...
tests/labelme_tests/utils_tests/test_shape.py
浏览文件 @
612b40df
...
@@ -10,7 +10,7 @@ def test_shapes_to_label():
...
@@ -10,7 +10,7 @@ def test_shapes_to_label():
label_name
=
shape
[
'label'
]
label_name
=
shape
[
'label'
]
label_value
=
len
(
label_name_to_value
)
label_value
=
len
(
label_name_to_value
)
label_name_to_value
[
label_name
]
=
label_value
label_name_to_value
[
label_name
]
=
label_value
cls
=
shape_module
.
shapes_to_label
(
cls
,
_
=
shape_module
.
shapes_to_label
(
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
assert
cls
.
shape
==
img
.
shape
[:
2
]
assert
cls
.
shape
==
img
.
shape
[:
2
]
...
...
tests/labelme_tests/utils_tests/util.py
浏览文件 @
612b40df
...
@@ -31,7 +31,7 @@ def get_img_and_lbl():
...
@@ -31,7 +31,7 @@ def get_img_and_lbl():
for
label_name
,
label_value
in
label_name_to_value
.
items
():
for
label_name
,
label_value
in
label_name_to_value
.
items
():
label_names
[
label_value
]
=
label_name
label_names
[
label_value
]
=
label_name
lbl
=
shape_module
.
shapes_to_label
(
lbl
,
_
=
shape_module
.
shapes_to_label
(
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
img
.
shape
,
data
[
'shapes'
],
label_name_to_value
)
)
return
img
,
lbl
,
label_names
return
img
,
lbl
,
label_names
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录