Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
VisualDL
提交
66a17d70
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看板
提交
66a17d70
编写于
12月 24, 2017
作者:
S
superjom
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
finish test
上级
5895b7e6
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
53 addition
and
29 deletion
+53
-29
visualdl/logic/pybind.cc
visualdl/logic/pybind.cc
+12
-9
visualdl/logic/sdk.h
visualdl/logic/sdk.h
+16
-6
visualdl/logic/sdk_test.cc
visualdl/logic/sdk_test.cc
+8
-7
visualdl/python/storage.py
visualdl/python/storage.py
+6
-2
visualdl/python/test_summary.py
visualdl/python/test_summary.py
+3
-3
visualdl/storage/storage.h
visualdl/storage/storage.h
+7
-2
visualdl/storage/tablet.h
visualdl/storage/tablet.h
+1
-0
未找到文件。
visualdl/logic/pybind.cc
浏览文件 @
66a17d70
...
...
@@ -15,7 +15,7 @@ PYBIND11_PLUGIN(core) {
py::class_<cp::ScalarReader<T>>(m, "ScalarReader__" #T) \
.def("records", &cp::ScalarReader<T>::records) \
.def("timestamps", &cp::ScalarReader<T>::timestamps) \
.def("caption
s", &cp::ScalarReader<T>::captions
);
.def("caption
", &cp::ScalarReader<T>::caption
);
ADD_SCALAR
(
int
);
ADD_SCALAR
(
float
);
ADD_SCALAR
(
double
);
...
...
@@ -56,11 +56,14 @@ PYBIND11_PLUGIN(core) {
})
py
::
class_
<
vs
::
Writer
>
(
m
,
"Writer"
)
.
def
(
"__init__"
,
.
def
(
"__init__"
,
[](
vs
::
Writer
&
instance
,
const
std
::
string
&
mode
,
const
std
::
string
&
dir
)
{
new
(
&
instance
)
vs
::
Writer
(
mode
,
dir
);
})
const
std
::
string
&
dir
,
int
sync_cycle
)
{
new
(
&
instance
)
vs
::
Writer
(
dir
);
instance
.
storage
().
meta
.
cycle
=
sync_cycle
;
})
.
def
(
"as_mode"
,
&
vs
::
Writer
::
AsMode
)
// clang-format off
ADD_SCALAR
(
float
)
ADD_SCALAR
(
double
)
...
...
visualdl/logic/sdk.h
浏览文件 @
66a17d70
...
...
@@ -8,15 +8,23 @@ namespace visualdl {
class
Writer
{
public:
Writer
(
const
std
::
string
&
mode
,
const
std
::
string
&
dir
)
:
mode_
(
mode
)
{
Writer
(
const
std
::
string
&
dir
)
{
storage_
.
SetDir
(
dir
);
}
Writer
&
AsMode
(
const
std
::
string
&
mode
)
{
mode_
=
mode
;
storage_
.
AddMode
(
mode
);
return
*
this
;
}
Tablet
AddTablet
(
const
std
::
string
&
tag
)
{
// TODO(ChunweiYan) add string check here.
auto
tmp
=
mode_
+
"/"
+
tag
;
string
::
TagEncode
(
tmp
);
return
storage_
.
AddTablet
(
tmp
);
auto
res
=
storage_
.
AddTablet
(
tmp
);
res
.
SetCaptions
(
std
::
vector
<
std
::
string
>
({
mode_
}));
return
res
;
}
Storage
&
storage
()
{
return
storage_
;
}
...
...
@@ -39,7 +47,7 @@ public:
private:
StorageReader
reader_
;
std
::
string
mode_
;
std
::
string
mode_
{
"default"
}
;
};
namespace
components
{
...
...
@@ -75,7 +83,8 @@ struct ScalarReader {
std
::
vector
<
T
>
records
()
const
;
std
::
vector
<
T
>
ids
()
const
;
std
::
vector
<
T
>
timestamps
()
const
;
std
::
vector
<
std
::
string
>
captions
()
const
;
std
::
string
caption
()
const
;
size_t
total_records
()
{
return
reader_
.
total_records
();}
size_t
size
()
const
;
private:
...
...
@@ -110,8 +119,9 @@ std::vector<T> ScalarReader<T>::timestamps() const {
}
template
<
typename
T
>
std
::
vector
<
std
::
string
>
ScalarReader
<
T
>::
captions
()
const
{
return
reader_
.
captions
();
std
::
string
ScalarReader
<
T
>::
caption
()
const
{
CHECK
(
!
reader_
.
captions
().
empty
())
<<
"no caption"
;
return
reader_
.
captions
().
front
();
}
template
<
typename
T
>
...
...
visualdl/logic/sdk_test.cc
浏览文件 @
66a17d70
...
...
@@ -14,18 +14,19 @@ TEST(Scalar, write) {
components
::
Scalar
<
int
>
scalar
(
tablet
);
scalar
.
SetCaption
(
"train"
);
scalar
.
AddRecord
(
0
,
12
);
storage
.
PersistToDisk
();
// read from disk
StorageReader
reader
(
dir
);
auto
scalar
_reader
=
reader
.
tablet
(
"scalar0"
);
auto
captioins
=
scalar_reader
.
captions
(
);
ASSERT_EQ
(
captioins
.
size
(),
1
);
ASSERT_EQ
(
captioin
s
.
front
()
,
"train"
);
auto
tablet
_reader
=
reader
.
tablet
(
"scalar0"
);
auto
scalar_reader
=
components
::
ScalarReader
<
int
>
(
std
::
move
(
tablet_reader
)
);
auto
captioin
=
scalar_reader
.
caption
(
);
ASSERT_EQ
(
captioin
,
"train"
);
ASSERT_EQ
(
scalar_reader
.
total_records
(),
1
);
auto
record
=
scalar_reader
.
record
(
0
);
auto
record
=
scalar_reader
.
records
();
ASSERT_EQ
(
record
.
size
(),
1
);
// check the first entry of first record
auto
vs
=
record
.
data
<
int
>
(
0
).
Get
();
ASSERT_EQ
(
vs
,
12
);
ASSERT_EQ
(
record
.
front
(),
12
);
}
}
// namespace visualdl
visualdl/python/storage.py
浏览文件 @
66a17d70
...
...
@@ -23,8 +23,12 @@ class StorageReader(object):
class
StorageWriter
(
object
):
def
__init__
(
self
,
mode
,
dir
):
self
.
writer
=
core
.
Writer
(
mode
,
dir
)
def
__init__
(
self
,
dir
,
sync_cycle
):
self
.
writer
=
core
.
Writer
(
dir
,
sync_cycle
)
def
as_mode
(
self
,
mode
):
self
.
writer
=
self
.
writer
.
as_mode
(
mode
)
return
self
def
scalar
(
self
,
tag
,
type
=
'float'
):
type2scalar
=
{
...
...
visualdl/python/test_summary.py
浏览文件 @
66a17d70
...
...
@@ -7,18 +7,18 @@ import time
class
StorageTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
dir
=
"./tmp/storage_test"
self
.
writer
=
storage
.
StorageWriter
(
"train"
,
self
.
dir
)
self
.
writer
=
storage
.
StorageWriter
(
self
.
dir
,
sync_cycle
=
1
).
as_mode
(
"train"
)
def
test_write
(
self
):
scalar
=
self
.
writer
.
scalar
(
"model/scalar/min"
)
scalar
.
set_caption
(
"model/scalar/min"
)
for
i
in
range
(
10
):
scalar
.
add_record
(
i
,
[
1.0
]
)
scalar
.
add_record
(
i
,
1.0
)
def
test_read
(
self
):
self
.
reader
=
storage
.
StorageReader
(
"train"
,
self
.
dir
)
scalar
=
self
.
reader
.
scalar
(
"model/scalar/min"
)
self
.
assertEqual
(
scalar
.
get_caption
(),
"model/scalar/m
in"
)
self
.
assertEqual
(
scalar
.
caption
(),
"tra
in"
)
if
__name__
==
'__main__'
:
...
...
visualdl/storage/storage.h
浏览文件 @
66a17d70
...
...
@@ -2,10 +2,11 @@
#define VISUALDL_STORAGE_STORAGE_H
#include <glog/logging.h>
#include <visualdl/utils/guard.h>
#include <vector>
#include <set>
#include "visualdl/logic/im.h"
#include "visualdl/utils/guard.h"
#include "visualdl/storage/storage.pb.h"
#include "visualdl/storage/tablet.h"
#include "visualdl/utils/filesystem.h"
...
...
@@ -49,7 +50,10 @@ struct Storage {
// write operations
void
AddMode
(
const
std
::
string
&
x
)
{
// avoid duplicate modes.
if
(
modes_
.
count
(
x
)
!=
0
)
return
;
*
data_
->
add_modes
()
=
x
;
modes_
.
insert
(
x
);
WRITE_GUARD
}
...
...
@@ -68,7 +72,7 @@ struct Storage {
* Save memory to disk.
*/
void
PersistToDisk
(
const
std
::
string
&
dir
)
{
LOG
(
INFO
)
<<
"persist to disk "
<<
dir
;
//
LOG(INFO) << "persist to disk " << dir;
CHECK
(
!
dir
.
empty
())
<<
"dir should be set."
;
fs
::
TryRecurMkdir
(
dir
);
...
...
@@ -91,6 +95,7 @@ private:
std
::
string
dir_
;
std
::
map
<
std
::
string
,
storage
::
Tablet
>
tablets_
;
std
::
shared_ptr
<
storage
::
Storage
>
data_
;
std
::
set
<
std
::
string
>
modes_
;
};
/*
...
...
visualdl/storage/tablet.h
浏览文件 @
66a17d70
...
...
@@ -48,6 +48,7 @@ struct Tablet {
}
void
SetCaptions
(
const
std
::
vector
<
std
::
string
>&
xs
)
{
data_
->
clear_captions
();
for
(
const
auto
&
x
:
xs
)
{
*
data_
->
add_captions
()
=
x
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录