Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
a6d71532
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
699
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看板
未验证
提交
a6d71532
编写于
12月 09, 2020
作者:
G
Guanghua Yu
提交者:
GitHub
12月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Cherry pick] support visualdl in preprocess data (#1842)
* support visualdl in preprocess data * support most preprocess op
上级
e0441f0d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
56 addition
and
7 deletion
+56
-7
ppdet/data/transform/operators.py
ppdet/data/transform/operators.py
+56
-7
未找到文件。
ppdet/data/transform/operators.py
浏览文件 @
a6d71532
...
...
@@ -33,9 +33,10 @@ import random
import
math
import
numpy
as
np
import
os
import
six
import
cv2
from
PIL
import
Image
,
ImageEnhance
,
ImageDraw
from
PIL
import
Image
,
ImageEnhance
,
ImageDraw
,
ImageOps
from
ppdet.core.workspace
import
serializable
from
ppdet.modeling.ops
import
AnchorGrid
...
...
@@ -2535,22 +2536,65 @@ class DebugVisibleImage(BaseOperator):
(Currently only supported when not cropping and flipping image.)
"""
def
__init__
(
self
,
output_dir
=
'output/debug'
,
is_normalized
=
False
):
def
__init__
(
self
,
output_dir
=
'output/debug'
,
use_vdl
=
False
,
is_normalized
=
False
):
super
(
DebugVisibleImage
,
self
).
__init__
()
self
.
is_normalized
=
is_normalized
self
.
output_dir
=
output_dir
self
.
use_vdl
=
use_vdl
if
not
os
.
path
.
isdir
(
output_dir
):
os
.
makedirs
(
output_dir
)
if
not
isinstance
(
self
.
is_normalized
,
bool
):
raise
TypeError
(
"{}: input type is invalid."
.
format
(
self
))
if
self
.
use_vdl
:
assert
six
.
PY3
,
"VisualDL requires Python >= 3.5"
from
visualdl
import
LogWriter
self
.
vdl_writer
=
LogWriter
(
self
.
output_dir
)
def
__call__
(
self
,
sample
,
context
=
None
):
image
=
Image
.
open
(
sample
[
'im_file'
]).
convert
(
'RGB'
)
out_file_name
=
sample
[
'im_file'
].
split
(
'/'
)[
-
1
]
if
self
.
use_vdl
:
origin_image
=
Image
.
open
(
sample
[
'im_file'
]).
convert
(
'RGB'
)
origin_image
=
ImageOps
.
exif_transpose
(
origin_image
)
image_np
=
np
.
array
(
origin_image
)
self
.
vdl_writer
.
add_image
(
"original/{}"
.
format
(
out_file_name
),
image_np
,
0
)
if
not
isinstance
(
sample
[
'image'
],
np
.
ndarray
):
raise
TypeError
(
"{}: sample[image] type is not numpy."
.
format
(
self
))
image
=
Image
.
fromarray
(
np
.
uint8
(
sample
[
'image'
]))
width
=
sample
[
'w'
]
height
=
sample
[
'h'
]
gt_bbox
=
sample
[
'gt_bbox'
]
gt_class
=
sample
[
'gt_class'
]
if
'gt_poly'
in
sample
.
keys
():
poly_to_mask
=
Poly2Mask
()
sample
=
poly_to_mask
(
sample
)
if
'gt_segm'
in
sample
.
keys
():
import
pycocotools.mask
as
mask_util
from
ppdet.utils.colormap
import
colormap
image_np
=
np
.
array
(
image
).
astype
(
'float32'
)
mask_color_id
=
0
w_ratio
=
.
4
alpha
=
0.7
color_list
=
colormap
(
rgb
=
True
)
gt_segm
=
sample
[
'gt_segm'
]
for
mask
in
gt_segm
:
color_mask
=
color_list
[
mask_color_id
%
len
(
color_list
),
0
:
3
]
mask_color_id
+=
1
for
c
in
range
(
3
):
color_mask
[
c
]
=
color_mask
[
c
]
*
(
1
-
w_ratio
)
+
w_ratio
*
255
idx
=
np
.
nonzero
(
mask
)
image_np
[
idx
[
0
],
idx
[
1
],
:]
*=
1.0
-
alpha
image_np
[
idx
[
0
],
idx
[
1
],
:]
+=
alpha
*
color_mask
image
=
Image
.
fromarray
(
np
.
uint8
(
image_np
))
draw
=
ImageDraw
.
Draw
(
image
)
for
i
in
range
(
gt_bbox
.
shape
[
0
]):
if
self
.
is_normalized
:
...
...
@@ -2566,7 +2610,7 @@ class DebugVisibleImage(BaseOperator):
width
=
2
,
fill
=
'green'
)
# draw label
text
=
str
(
gt_class
[
i
][
0
])
text
=
'id'
+
str
(
gt_class
[
i
][
0
])
tw
,
th
=
draw
.
textsize
(
text
)
draw
.
rectangle
(
[(
xmin
+
1
,
ymin
-
th
),
(
xmin
+
tw
+
1
,
ymin
)],
fill
=
'green'
)
...
...
@@ -2583,12 +2627,17 @@ class DebugVisibleImage(BaseOperator):
for
i
in
range
(
gt_keypoint
.
shape
[
0
]):
keypoint
=
gt_keypoint
[
i
]
for
j
in
range
(
int
(
keypoint
.
shape
[
0
]
/
2
)):
x1
=
round
(
keypoint
[
2
*
j
])
.
astype
(
np
.
int32
)
y1
=
round
(
keypoint
[
2
*
j
+
1
])
.
astype
(
np
.
int32
)
x1
=
round
(
keypoint
[
2
*
j
])
y1
=
round
(
keypoint
[
2
*
j
+
1
])
draw
.
ellipse
(
(
x1
,
y1
,
x1
+
5
,
y1
+
5
),
fill
=
'green'
,
outline
=
'green'
)
save_path
=
os
.
path
.
join
(
self
.
output_dir
,
out_file_name
)
image
.
save
(
save_path
,
quality
=
95
)
if
self
.
use_vdl
:
preprocess_image_np
=
np
.
array
(
image
)
self
.
vdl_writer
.
add_image
(
"preprocess/{}"
.
format
(
out_file_name
),
preprocess_image_np
,
0
)
else
:
image
.
save
(
save_path
,
quality
=
95
)
return
sample
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录