Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleX
提交
02c8e574
P
PaddleX
项目概览
PaddlePaddle
/
PaddleX
通知
138
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
43
列表
看板
标记
里程碑
合并请求
5
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleX
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
43
Issue
43
列表
看板
标记
里程碑
合并请求
5
合并请求
5
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
02c8e574
编写于
5月 12, 2020
作者:
S
sunyanfang01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add comment
上级
8590cb53
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
8 deletion
+49
-8
paddlex/tools/x2coco.py
paddlex/tools/x2coco.py
+18
-8
paddlex/tools/x2imagenet.py
paddlex/tools/x2imagenet.py
+8
-0
paddlex/tools/x2seg.py
paddlex/tools/x2seg.py
+13
-0
paddlex/tools/x2voc.py
paddlex/tools/x2voc.py
+10
-0
未找到文件。
paddlex/tools/x2coco.py
浏览文件 @
02c8e574
...
@@ -55,22 +55,28 @@ class X2COCO(object):
...
@@ -55,22 +55,28 @@ class X2COCO(object):
annotation
[
"id"
]
=
object_id
+
1
annotation
[
"id"
]
=
object_id
+
1
return
annotation
return
annotation
def
convert
(
self
,
image_input_dir
,
json_input_dir
,
dataset_save_dir
):
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
assert
osp
.
exists
(
image_input_dir
),
"he image folder does not exist!"
"""转换。
assert
osp
.
exists
(
json_input_dir
),
"The json folder does not exist!"
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert
osp
.
exists
(
image_dir
),
"he image folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
# Convert the image files.
# Convert the image files.
new_image_dir
=
osp
.
join
(
dataset_save_dir
,
"JPEGImages"
)
new_image_dir
=
osp
.
join
(
dataset_save_dir
,
"JPEGImages"
)
if
osp
.
exists
(
new_image_dir
):
if
osp
.
exists
(
new_image_dir
):
shutil
.
rmtree
(
new_image_dir
)
shutil
.
rmtree
(
new_image_dir
)
os
.
makedirs
(
new_image_dir
)
os
.
makedirs
(
new_image_dir
)
for
img_name
in
os
.
listdir
(
image_
input_
dir
):
for
img_name
in
os
.
listdir
(
image_dir
):
if
is_pic
(
img_name
):
if
is_pic
(
img_name
):
shutil
.
copyfile
(
shutil
.
copyfile
(
osp
.
join
(
image_
input_
dir
,
img_name
),
osp
.
join
(
image_dir
,
img_name
),
osp
.
join
(
new_image_dir
,
img_name
))
osp
.
join
(
new_image_dir
,
img_name
))
# Convert the json files.
# Convert the json files.
self
.
analyse_json
(
new_image_dir
,
json_input
_dir
)
self
.
parse_json
(
new_image_dir
,
json
_dir
)
coco_data
=
{}
coco_data
=
{}
coco_data
[
"images"
]
=
self
.
images_list
coco_data
[
"images"
]
=
self
.
images_list
coco_data
[
"categories"
]
=
self
.
categories_list
coco_data
[
"categories"
]
=
self
.
categories_list
...
@@ -84,6 +90,8 @@ class X2COCO(object):
...
@@ -84,6 +90,8 @@ class X2COCO(object):
class
LabelMe2COCO
(
X2COCO
):
class
LabelMe2COCO
(
X2COCO
):
"""将使用LabelMe标注的数据集转换为COCO数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
super
(
LabelMe2COCO
,
self
).
__init__
()
super
(
LabelMe2COCO
,
self
).
__init__
()
...
@@ -127,7 +135,7 @@ class LabelMe2COCO(X2COCO):
...
@@ -127,7 +135,7 @@ class LabelMe2COCO(X2COCO):
right_bottom_r
-
left_top_r
right_bottom_r
-
left_top_r
]
]
def
analy
se_json
(
self
,
img_dir
,
json_dir
):
def
par
se_json
(
self
,
img_dir
,
json_dir
):
image_id
=
-
1
image_id
=
-
1
object_id
=
-
1
object_id
=
-
1
labels_list
=
[]
labels_list
=
[]
...
@@ -168,6 +176,8 @@ class LabelMe2COCO(X2COCO):
...
@@ -168,6 +176,8 @@ class LabelMe2COCO(X2COCO):
class
EasyData2COCO
(
X2COCO
):
class
EasyData2COCO
(
X2COCO
):
"""将使用EasyData标注的检测或分割数据集转换为COCO数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
super
(
EasyData2COCO
,
self
).
__init__
()
super
(
EasyData2COCO
,
self
).
__init__
()
...
@@ -196,7 +206,7 @@ class EasyData2COCO(X2COCO):
...
@@ -196,7 +206,7 @@ class EasyData2COCO(X2COCO):
annotation
[
"id"
]
=
object_id
+
1
annotation
[
"id"
]
=
object_id
+
1
return
annotation
return
annotation
def
analy
se_json
(
self
,
img_dir
,
json_dir
):
def
par
se_json
(
self
,
img_dir
,
json_dir
):
from
pycocotools.mask
import
decode
from
pycocotools.mask
import
decode
image_id
=
-
1
image_id
=
-
1
object_id
=
-
1
object_id
=
-
1
...
...
paddlex/tools/x2imagenet.py
浏览文件 @
02c8e574
...
@@ -23,10 +23,18 @@ import numpy as np
...
@@ -23,10 +23,18 @@ import numpy as np
from
.base
import
MyEncoder
,
is_pic
,
get_encoding
from
.base
import
MyEncoder
,
is_pic
,
get_encoding
class
EasyData2ImageNet
(
object
):
class
EasyData2ImageNet
(
object
):
"""将使用EasyData标注的分类数据集转换为COCO数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
"""转换。
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert
osp
.
exists
(
image_dir
),
"The image folder does not exist!"
assert
osp
.
exists
(
image_dir
),
"The image folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
...
...
paddlex/tools/x2seg.py
浏览文件 @
02c8e574
...
@@ -29,6 +29,7 @@ class X2Seg(object):
...
@@ -29,6 +29,7 @@ class X2Seg(object):
self
.
labels2ids
=
{
'_background_'
:
0
}
self
.
labels2ids
=
{
'_background_'
:
0
}
def
shapes_to_label
(
self
,
img_shape
,
shapes
,
label_name_to_value
):
def
shapes_to_label
(
self
,
img_shape
,
shapes
,
label_name_to_value
):
# This function is based on https://github.com/wkentaro/labelme/blob/master/labelme/utils/shape.py.
def
shape_to_mask
(
img_shape
,
points
,
shape_type
=
None
,
def
shape_to_mask
(
img_shape
,
points
,
shape_type
=
None
,
line_width
=
10
,
point_size
=
5
):
line_width
=
10
,
point_size
=
5
):
mask
=
np
.
zeros
(
img_shape
[:
2
],
dtype
=
np
.
uint8
)
mask
=
np
.
zeros
(
img_shape
[:
2
],
dtype
=
np
.
uint8
)
...
@@ -102,6 +103,12 @@ class X2Seg(object):
...
@@ -102,6 +103,12 @@ class X2Seg(object):
return
color_map
return
color_map
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
"""转换。
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert
osp
.
exists
(
image_dir
),
"The image folder does not exist!"
assert
osp
.
exists
(
image_dir
),
"The image folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
...
@@ -130,6 +137,8 @@ class X2Seg(object):
...
@@ -130,6 +137,8 @@ class X2Seg(object):
class
JingLing2Seg
(
X2Seg
):
class
JingLing2Seg
(
X2Seg
):
"""将使用标注精灵标注的数据集转换为Seg数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
super
(
JingLing2Seg
,
self
).
__init__
()
super
(
JingLing2Seg
,
self
).
__init__
()
...
@@ -198,6 +207,8 @@ class JingLing2Seg(X2Seg):
...
@@ -198,6 +207,8 @@ class JingLing2Seg(X2Seg):
class
LabelMe2Seg
(
X2Seg
):
class
LabelMe2Seg
(
X2Seg
):
"""将使用LabelMe标注的数据集转换为Seg数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
super
(
LabelMe2Seg
,
self
).
__init__
()
super
(
LabelMe2Seg
,
self
).
__init__
()
...
@@ -246,6 +257,8 @@ class LabelMe2Seg(X2Seg):
...
@@ -246,6 +257,8 @@ class LabelMe2Seg(X2Seg):
class
EasyData2Seg
(
X2Seg
):
class
EasyData2Seg
(
X2Seg
):
"""将使用EasyData标注的分割数据集转换为Seg数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
super
(
EasyData2Seg
,
self
).
__init__
()
super
(
EasyData2Seg
,
self
).
__init__
()
...
...
paddlex/tools/x2voc.py
浏览文件 @
02c8e574
...
@@ -27,6 +27,12 @@ class X2VOC(object):
...
@@ -27,6 +27,12 @@ class X2VOC(object):
pass
pass
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
def
convert
(
self
,
image_dir
,
json_dir
,
dataset_save_dir
):
"""转换。
Args:
image_dir (str): 图像文件存放的路径。
json_dir (str): 与每张图像对应的json文件的存放路径。
dataset_save_dir (str): 转换后数据集存放路径。
"""
assert
osp
.
exists
(
image_dir
),
"The image folder does not exist!"
assert
osp
.
exists
(
image_dir
),
"The image folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
json_dir
),
"The json folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
assert
osp
.
exists
(
dataset_save_dir
),
"The save folder does not exist!"
...
@@ -49,6 +55,8 @@ class X2VOC(object):
...
@@ -49,6 +55,8 @@ class X2VOC(object):
class
LabelMe2VOC
(
X2VOC
):
class
LabelMe2VOC
(
X2VOC
):
"""将使用LabelMe标注的数据集转换为VOC数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
...
@@ -119,6 +127,8 @@ class LabelMe2VOC(X2VOC):
...
@@ -119,6 +127,8 @@ class LabelMe2VOC(X2VOC):
class
EasyData2VOC
(
X2VOC
):
class
EasyData2VOC
(
X2VOC
):
"""将使用EasyData标注的分割数据集转换为VOC数据集。
"""
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录