Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
23391a43
V
VisualDL
项目概览
PaddlePaddle
/
VisualDL
大约 1 年 前同步成功
通知
88
Star
4655
Fork
642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
2
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
V
VisualDL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
23391a43
编写于
9月 08, 2020
作者:
走神的阿圆
提交者:
GitHub
9月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add dataformat of image (#801)
上级
5a19d2e6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
63 addition
and
3 deletion
+63
-3
visualdl/component/base_component.py
visualdl/component/base_component.py
+60
-1
visualdl/writer/writer.py
visualdl/writer/writer.py
+3
-2
未找到文件。
visualdl/component/base_component.py
浏览文件 @
23391a43
...
...
@@ -80,7 +80,65 @@ def imgarray2bytes(np_array):
return
img_bin
def
image
(
tag
,
image_array
,
step
,
walltime
=
None
):
def
make_grid
(
I
,
ncols
=
8
):
assert
isinstance
(
I
,
np
.
ndarray
),
'plugin error, should pass numpy array here'
if
I
.
shape
[
1
]
==
1
:
I
=
np
.
concatenate
([
I
,
I
,
I
],
1
)
assert
I
.
ndim
==
4
and
I
.
shape
[
1
]
==
3
or
I
.
shape
[
1
]
==
4
nimg
=
I
.
shape
[
0
]
H
=
I
.
shape
[
2
]
W
=
I
.
shape
[
3
]
ncols
=
min
(
nimg
,
ncols
)
nrows
=
int
(
np
.
ceil
(
float
(
nimg
)
/
ncols
))
canvas
=
np
.
zeros
((
I
.
shape
[
1
],
H
*
nrows
,
W
*
ncols
),
dtype
=
I
.
dtype
)
i
=
0
for
y
in
range
(
nrows
):
for
x
in
range
(
ncols
):
if
i
>=
nimg
:
break
canvas
[:,
y
*
H
:(
y
+
1
)
*
H
,
x
*
W
:(
x
+
1
)
*
W
]
=
I
[
i
]
i
=
i
+
1
return
canvas
def
convert_to_HWC
(
tensor
,
input_format
):
"""Convert `NCHW`, `HWC`, `HW` to `HWC`
Args:
tensor (numpy.ndarray): Value of image
input_format (string): Format of image
Return:
Image of format `HWC`.
"""
assert
(
len
(
set
(
input_format
))
==
len
(
input_format
)),
"You can not use the same dimension shordhand twice.
\
input_format: {}"
.
format
(
input_format
)
assert
(
len
(
tensor
.
shape
)
==
len
(
input_format
)),
"size of input tensor and input format are different.
\
tensor shape: {}, input_format: {}"
.
format
(
tensor
.
shape
,
input_format
)
input_format
=
input_format
.
upper
()
if
len
(
input_format
)
==
4
:
index
=
[
input_format
.
find
(
c
)
for
c
in
'NCHW'
]
tensor_NCHW
=
tensor
.
transpose
(
index
)
tensor_CHW
=
make_grid
(
tensor_NCHW
)
return
tensor_CHW
.
transpose
(
1
,
2
,
0
)
if
len
(
input_format
)
==
3
:
index
=
[
input_format
.
find
(
c
)
for
c
in
'HWC'
]
tensor_HWC
=
tensor
.
transpose
(
index
)
if
tensor_HWC
.
shape
[
2
]
==
1
:
tensor_HWC
=
np
.
concatenate
([
tensor_HWC
,
tensor_HWC
,
tensor_HWC
],
2
)
return
tensor_HWC
if
len
(
input_format
)
==
2
:
index
=
[
input_format
.
find
(
c
)
for
c
in
'HW'
]
tensor
=
tensor
.
transpose
(
index
)
tensor
=
np
.
stack
([
tensor
,
tensor
,
tensor
],
2
)
return
tensor
def
image
(
tag
,
image_array
,
step
,
walltime
=
None
,
dataformats
=
"HWC"
):
"""Package data to one image.
Args:
...
...
@@ -92,6 +150,7 @@ def image(tag, image_array, step, walltime=None):
Return:
Package with format of record_pb2.Record
"""
image_array
=
convert_to_HWC
(
image_array
,
dataformats
)
image_bytes
=
imgarray2bytes
(
image_array
)
image
=
Record
.
Image
(
encoded_image_string
=
image_bytes
)
return
Record
(
values
=
[
...
...
visualdl/writer/writer.py
浏览文件 @
23391a43
...
...
@@ -163,7 +163,7 @@ class LogWriter(object):
self
.
_get_file_writer
().
add_record
(
scalar
(
tag
=
tag
,
value
=
value
,
step
=
step
,
walltime
=
walltime
))
def
add_image
(
self
,
tag
,
img
,
step
,
walltime
=
None
):
def
add_image
(
self
,
tag
,
img
,
step
,
walltime
=
None
,
dataformats
=
"HWC"
):
"""Add an image to vdl record file.
Args:
...
...
@@ -184,7 +184,8 @@ class LogWriter(object):
raise
RuntimeError
(
"% can't appear in tag!"
)
walltime
=
round
(
time
.
time
()
*
1000
)
if
walltime
is
None
else
walltime
self
.
_get_file_writer
().
add_record
(
image
(
tag
=
tag
,
image_array
=
img
,
step
=
step
,
walltime
=
walltime
))
image
(
tag
=
tag
,
image_array
=
img
,
step
=
step
,
walltime
=
walltime
,
dataformats
=
dataformats
))
def
add_embeddings
(
self
,
tag
,
labels
,
hot_vectors
,
walltime
=
None
):
"""Add embeddings to vdl record file.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录