Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
6e851dc5
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6e851dc5
编写于
10月 23, 2019
作者:
S
SunAhong1993
提交者:
GitHub
10月 23, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the labelme2coco.py (#3726)
* fix the labelme2coco.py * fix the labelme2coco.py
上级
1653822e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
13 addition
and
11 deletion
+13
-11
ppdet/data/tools/labelme2coco.py
ppdet/data/tools/labelme2coco.py
+13
-11
未找到文件。
ppdet/data/tools/labelme2coco.py
浏览文件 @
6e851dc5
...
@@ -61,14 +61,14 @@ def categories(label, labels_list):
...
@@ -61,14 +61,14 @@ def categories(label, labels_list):
return
category
return
category
def
annotations_rectangle
(
points
,
label
,
num
,
label_to_num
):
def
annotations_rectangle
(
points
,
label
,
image_num
,
object_
num
,
label_to_num
):
annotation
=
{}
annotation
=
{}
seg_points
=
np
.
asarray
(
points
).
copy
()
seg_points
=
np
.
asarray
(
points
).
copy
()
seg_points
[
1
,
:]
=
np
.
asarray
(
points
)[
2
,
:]
seg_points
[
1
,
:]
=
np
.
asarray
(
points
)[
2
,
:]
seg_points
[
2
,
:]
=
np
.
asarray
(
points
)[
1
,
:]
seg_points
[
2
,
:]
=
np
.
asarray
(
points
)[
1
,
:]
annotation
[
'segmentation'
]
=
[
list
(
seg_points
.
flatten
())]
annotation
[
'segmentation'
]
=
[
list
(
seg_points
.
flatten
())]
annotation
[
'iscrowd'
]
=
0
annotation
[
'iscrowd'
]
=
0
annotation
[
'image_id'
]
=
num
+
1
annotation
[
'image_id'
]
=
image_
num
+
1
annotation
[
'bbox'
]
=
list
(
annotation
[
'bbox'
]
=
list
(
map
(
float
,
[
map
(
float
,
[
points
[
0
][
0
],
points
[
0
][
1
],
points
[
1
][
0
]
-
points
[
0
][
0
],
points
[
1
][
points
[
0
][
0
],
points
[
0
][
1
],
points
[
1
][
0
]
-
points
[
0
][
0
],
points
[
1
][
...
@@ -76,19 +76,19 @@ def annotations_rectangle(points, label, num, label_to_num):
...
@@ -76,19 +76,19 @@ def annotations_rectangle(points, label, num, label_to_num):
]))
]))
annotation
[
'area'
]
=
annotation
[
'bbox'
][
2
]
*
annotation
[
'bbox'
][
3
]
annotation
[
'area'
]
=
annotation
[
'bbox'
][
2
]
*
annotation
[
'bbox'
][
3
]
annotation
[
'category_id'
]
=
label_to_num
[
label
]
annotation
[
'category_id'
]
=
label_to_num
[
label
]
annotation
[
'id'
]
=
num
+
1
annotation
[
'id'
]
=
object_
num
+
1
return
annotation
return
annotation
def
annotations_polygon
(
height
,
width
,
points
,
label
,
num
,
label_to_num
):
def
annotations_polygon
(
height
,
width
,
points
,
label
,
image_num
,
object_
num
,
label_to_num
):
annotation
=
{}
annotation
=
{}
annotation
[
'segmentation'
]
=
[
list
(
np
.
asarray
(
points
).
flatten
())]
annotation
[
'segmentation'
]
=
[
list
(
np
.
asarray
(
points
).
flatten
())]
annotation
[
'iscrowd'
]
=
0
annotation
[
'iscrowd'
]
=
0
annotation
[
'image_id'
]
=
num
+
1
annotation
[
'image_id'
]
=
image_
num
+
1
annotation
[
'bbox'
]
=
list
(
map
(
float
,
get_bbox
(
height
,
width
,
points
)))
annotation
[
'bbox'
]
=
list
(
map
(
float
,
get_bbox
(
height
,
width
,
points
)))
annotation
[
'area'
]
=
annotation
[
'bbox'
][
2
]
*
annotation
[
'bbox'
][
3
]
annotation
[
'area'
]
=
annotation
[
'bbox'
][
2
]
*
annotation
[
'bbox'
][
3
]
annotation
[
'category_id'
]
=
label_to_num
[
label
]
annotation
[
'category_id'
]
=
label_to_num
[
label
]
annotation
[
'id'
]
=
num
+
1
annotation
[
'id'
]
=
object_
num
+
1
return
annotation
return
annotation
...
@@ -119,16 +119,18 @@ def deal_json(img_path, json_path):
...
@@ -119,16 +119,18 @@ def deal_json(img_path, json_path):
categories_list
=
[]
categories_list
=
[]
annotations_list
=
[]
annotations_list
=
[]
labels_list
=
[]
labels_list
=
[]
num
=
-
1
image_
num
=
-
1
for
img_file
in
os
.
listdir
(
img_path
):
for
img_file
in
os
.
listdir
(
img_path
):
img_label
=
img_file
.
split
(
'.'
)[
0
]
img_label
=
img_file
.
split
(
'.'
)[
0
]
label_file
=
osp
.
join
(
json_path
,
img_label
+
'.json'
)
label_file
=
osp
.
join
(
json_path
,
img_label
+
'.json'
)
print
(
'Generating dataset from:'
,
label_file
)
print
(
'Generating dataset from:'
,
label_file
)
num
=
num
+
1
image_num
=
image_
num
+
1
with
open
(
label_file
)
as
f
:
with
open
(
label_file
)
as
f
:
data
=
json
.
load
(
f
)
data
=
json
.
load
(
f
)
images_list
.
append
(
images
(
data
,
num
))
images_list
.
append
(
images
(
data
,
image_num
))
object_num
=
-
1
for
shapes
in
data
[
'shapes'
]:
for
shapes
in
data
[
'shapes'
]:
object_num
=
object_num
+
1
label
=
shapes
[
'label'
]
label
=
shapes
[
'label'
]
if
label
not
in
labels_list
:
if
label
not
in
labels_list
:
categories_list
.
append
(
categories
(
label
,
labels_list
))
categories_list
.
append
(
categories
(
label
,
labels_list
))
...
@@ -139,13 +141,13 @@ def deal_json(img_path, json_path):
...
@@ -139,13 +141,13 @@ def deal_json(img_path, json_path):
if
p_type
==
'polygon'
:
if
p_type
==
'polygon'
:
annotations_list
.
append
(
annotations_list
.
append
(
annotations_polygon
(
data
[
'imageHeight'
],
data
[
annotations_polygon
(
data
[
'imageHeight'
],
data
[
'imageWidth'
],
points
,
label
,
num
,
label_to_num
))
'imageWidth'
],
points
,
label
,
image_num
,
object_
num
,
label_to_num
))
if
p_type
==
'rectangle'
:
if
p_type
==
'rectangle'
:
points
.
append
([
points
[
0
][
0
],
points
[
1
][
1
]])
points
.
append
([
points
[
0
][
0
],
points
[
1
][
1
]])
points
.
append
([
points
[
1
][
0
],
points
[
0
][
1
]])
points
.
append
([
points
[
1
][
0
],
points
[
0
][
1
]])
annotations_list
.
append
(
annotations_list
.
append
(
annotations_rectangle
(
points
,
label
,
num
,
label_to_num
))
annotations_rectangle
(
points
,
label
,
image_num
,
object_
num
,
label_to_num
))
data_coco
[
'images'
]
=
images_list
data_coco
[
'images'
]
=
images_list
data_coco
[
'categories'
]
=
categories_list
data_coco
[
'categories'
]
=
categories_list
data_coco
[
'annotations'
]
=
annotations_list
data_coco
[
'annotations'
]
=
annotations_list
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录