Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
beb1e3b5
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看板
提交
beb1e3b5
编写于
12月 18, 2017
作者:
S
superjom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add read and write to test_summary.py
上级
11e04871
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
69 addition
and
10 deletion
+69
-10
visualdl/python/test_summary.py
visualdl/python/test_summary.py
+63
-4
visualdl/storage/storage.cc
visualdl/storage/storage.cc
+5
-5
visualdl/utils/filesystem.h
visualdl/utils/filesystem.h
+1
-1
未找到文件。
visualdl/python/test_summary.py
浏览文件 @
beb1e3b5
import
summary
import
numpy
as
np
import
unittest
import
random
import
time
once_flag
=
False
...
...
@@ -8,14 +9,21 @@ once_flag = False
class
ScalarTester
(
unittest
.
TestCase
):
def
setUp
(
self
):
dir
=
"tmp/3.test"
self
.
im
=
summary
.
IM
(
"write"
,
dir
)
self
.
scalar
=
summary
.
scalar
(
self
.
im
,
"scalar0"
)
self
.
dir
=
"tmp/summary.test"
# clean path
try
:
os
.
rmdir
(
self
.
dir
)
except
:
pass
self
.
im
=
summary
.
IM
(
self
.
dir
,
"write"
,
200
)
self
.
tablet_name
=
"scalar0"
self
.
scalar
=
summary
.
scalar
(
self
.
im
,
self
.
tablet_name
)
self
.
py_captions
=
[
"train cost"
,
"test cost"
]
self
.
scalar
.
set_captions
(
self
.
py_captions
)
self
.
py_records
=
[]
self
.
py_ids
=
[]
# write
for
i
in
range
(
10
):
record
=
[
0.1
*
i
,
0.2
*
i
]
id
=
i
*
10
...
...
@@ -23,7 +31,6 @@ class ScalarTester(unittest.TestCase):
self
.
py_ids
.
append
(
id
)
self
.
scalar
.
add
(
id
,
record
)
def
test_records
(
self
):
self
.
assertEqual
(
self
.
scalar
.
size
,
len
(
self
.
py_records
))
for
i
,
record
in
enumerate
(
self
.
scalar
.
records
):
...
...
@@ -37,6 +44,58 @@ class ScalarTester(unittest.TestCase):
def
test_captions
(
self
):
self
.
assertEqual
(
self
.
scalar
.
captions
,
self
.
py_captions
)
def
test_read_records
(
self
):
time
.
sleep
(
1
)
im
=
summary
.
IM
(
self
.
dir
,
"read"
,
200
)
time
.
sleep
(
1
)
scalar
=
summary
.
scalar
(
im
,
self
.
tablet_name
)
records
=
scalar
.
records
self
.
assertEqual
(
len
(
self
.
py_records
),
scalar
.
size
)
for
i
,
record
in
enumerate
(
self
.
scalar
.
records
):
self
.
assertTrue
(
np
.
isclose
(
record
,
records
[
i
]).
all
())
def
test_read_ids
(
self
):
time
.
sleep
(
0.6
)
im
=
summary
.
IM
(
self
.
dir
,
"read"
,
msecs
=
200
)
time
.
sleep
(
0.6
)
scalar
=
summary
.
scalar
(
im
,
self
.
tablet_name
)
self
.
assertEqual
(
len
(
self
.
py_ids
),
scalar
.
size
)
for
i
,
id
in
enumerate
(
scalar
.
ids
):
self
.
assertEqual
(
self
.
py_ids
[
i
],
id
)
def
test_read_captions
(
self
):
time
.
sleep
(
0.6
)
im
=
summary
.
IM
(
self
.
dir
,
"read"
,
msecs
=
200
)
time
.
sleep
(
0.6
)
scalar
=
summary
.
scalar
(
im
,
self
.
tablet_name
)
self
.
assertEqual
(
scalar
.
captions
,
self
.
py_captions
)
def
test_mix_read_write
(
self
):
write_im
=
summary
.
IM
(
self
.
dir
,
"write"
,
msecs
=
200
)
time
.
sleep
(
0.6
)
read_im
=
summary
.
IM
(
self
.
dir
,
"read"
,
msecs
=
200
)
scalar_writer
=
summary
.
scalar
(
write_im
,
self
.
tablet_name
)
scalar_reader
=
summary
.
scalar
(
read_im
,
self
.
tablet_name
)
scalar_writer
.
set_captions
([
"train cost"
,
"test cost"
])
for
i
in
range
(
1000
):
scalar_writer
.
add
(
i
,
[
random
.
random
(),
random
.
random
()])
scalar_reader
.
records
for
i
in
range
(
500
):
scalar_writer
.
add
(
i
,
[
random
.
random
(),
random
.
random
()])
scalar_reader
.
records
for
i
in
range
(
500
):
scalar_writer
.
add
(
i
,
[
random
.
random
(),
random
.
random
()])
for
i
in
range
(
10
):
scalar_reader
.
records
scalar_reader
.
captions
if
__name__
==
'__main__'
:
unittest
.
main
()
visualdl/storage/storage.cc
浏览文件 @
beb1e3b5
...
...
@@ -46,9 +46,9 @@ void MemoryStorage::PersistToDisk(const std::string &dir) {
// make a directory if not exist
fs
::
TryRecurMkdir
(
dir
);
// write storage out
LOG
(
INFO
)
<<
"to serize meta to dir "
<<
dir
;
VLOG
(
2
)
<<
"to serize meta to dir "
<<
dir
;
fs
::
SerializeToFile
(
storage_
,
meta_path
(
dir
));
LOG
(
INFO
)
<<
"serize meta to dir "
<<
dir
;
VLOG
(
2
)
<<
"serize meta to dir "
<<
dir
;
// write all the tablets
for
(
auto
tag
:
storage_
.
tags
())
{
auto
it
=
tablets_
.
find
(
tag
);
...
...
@@ -77,7 +77,7 @@ void MemoryStorage::StartReadService(const std::string &dir,
CHECK
(
executor_
!=
nullptr
);
CHECK
(
!
dir
.
empty
())
<<
"dir should be set first"
;
cc
::
PeriodExector
::
task_t
task
=
[
dir
,
this
,
handler
]
{
LOG
(
INFO
)
<<
"loading from "
<<
dir
;
VLOG
(
1
)
<<
"loading from "
<<
dir
;
if
(
handler
!=
nullptr
)
{
std
::
lock_guard
<
std
::
mutex
>
_
(
*
handler
);
LoadFromDisk
(
dir
);
...
...
@@ -87,7 +87,7 @@ void MemoryStorage::StartReadService(const std::string &dir,
return
true
;
};
// executor_.Start();
LOG
(
INFO
)
<<
"push read task"
;
VLOG
(
1
)
<<
"push read task"
;
(
*
executor_
)(
std
::
move
(
task
),
msecs
);
}
...
...
@@ -99,7 +99,7 @@ void MemoryStorage::StartWriteService(const std::string &dir,
storage_
.
set_dir
(
dir
);
// executor_.Start();
cc
::
PeriodExector
::
task_t
task
=
[
dir
,
handler
,
this
]
{
LOG
(
INFO
)
<<
"persist to disk"
;
VLOG
(
2
)
<<
"persist to disk"
;
if
(
handler
!=
nullptr
)
{
std
::
lock_guard
<
std
::
mutex
>
_
(
*
handler
);
PersistToDisk
(
dir
);
...
...
visualdl/utils/filesystem.h
浏览文件 @
beb1e3b5
...
...
@@ -44,7 +44,7 @@ bool DeSerializeFromFile(T* proto, const std::string& path) {
}
void
TryMkdir
(
const
std
::
string
&
dir
)
{
LOG
(
INFO
)
<<
"try to mkdir "
<<
dir
;
VLOG
(
1
)
<<
"try to mkdir "
<<
dir
;
struct
stat
st
=
{
0
};
if
(
stat
(
dir
.
c_str
(),
&
st
)
==
-
1
)
{
::
mkdir
(
dir
.
c_str
(),
0700
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录