Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
34301732
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
1 年多 前同步成功
通知
696
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看板
未验证
提交
34301732
编写于
5月 27, 2019
作者:
C
chengduo
提交者:
GitHub
5月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish Print Op (#17651)
* enhance print
上级
4aa931dd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
36 addition
and
16 deletion
+36
-16
paddle/fluid/operators/print_op.cc
paddle/fluid/operators/print_op.cc
+36
-16
未找到文件。
paddle/fluid/operators/print_op.cc
浏览文件 @
34301732
...
...
@@ -26,6 +26,19 @@ const char kForward[] = "FORWARD";
const
char
kBackward
[]
=
"BACKWARD"
;
const
char
kBoth
[]
=
"BOTH"
;
class
LogGuard
{
public:
inline
LogGuard
()
{
LogMutex
().
lock
();
}
inline
~
LogGuard
()
{
LogMutex
().
unlock
();
}
private:
static
std
::
mutex
&
LogMutex
()
{
static
std
::
mutex
mtx
;
return
mtx
;
}
};
struct
Formater
{
std
::
string
message
;
std
::
string
name
;
...
...
@@ -34,48 +47,54 @@ struct Formater {
framework
::
LoD
lod
;
int
summarize
;
void
*
data
{
nullptr
};
platform
::
Place
place
;
std
::
stringstream
logs
;
void
operator
()(
size_t
size
)
{
PrintMessage
();
PrintPlaceInfo
();
PrintName
();
PrintDims
();
PrintDtype
();
PrintLod
();
PrintData
(
size
);
LogGuard
guard
;
CLOG
<<
logs
.
str
();
}
private:
void
PrintMessage
()
{
CLOG
<<
std
::
time
(
nullptr
)
<<
"
\t
"
<<
message
<<
"
\t
"
;
}
void
PrintPlaceInfo
()
{
logs
<<
"The place is:"
<<
place
<<
std
::
endl
;
}
void
PrintMessage
()
{
logs
<<
std
::
time
(
nullptr
)
<<
"
\t
"
<<
message
<<
"
\t
"
;
}
void
PrintName
()
{
if
(
!
name
.
empty
())
{
CLOG
<<
"Tensor["
<<
name
<<
"]"
<<
std
::
endl
;
logs
<<
"Tensor["
<<
name
<<
"]"
<<
std
::
endl
;
}
}
void
PrintDims
()
{
if
(
!
dims
.
empty
())
{
CLOG
<<
"
\t
shape: ["
;
logs
<<
"
\t
shape: ["
;
for
(
auto
i
:
dims
)
{
CLOG
<<
i
<<
","
;
logs
<<
i
<<
","
;
}
CLOG
<<
"]"
<<
std
::
endl
;
logs
<<
"]"
<<
std
::
endl
;
}
}
void
PrintDtype
()
{
if
(
!
framework
::
IsType
<
const
char
>
(
dtype
))
{
CLOG
<<
"
\t
dtype: "
<<
dtype
.
name
()
<<
std
::
endl
;
logs
<<
"
\t
dtype: "
<<
dtype
.
name
()
<<
std
::
endl
;
}
}
void
PrintLod
()
{
if
(
!
lod
.
empty
())
{
CLOG
<<
"
\t
LoD: ["
;
logs
<<
"
\t
LoD: ["
;
for
(
auto
level
:
lod
)
{
CLOG
<<
"[ "
;
logs
<<
"[ "
;
for
(
auto
i
:
level
)
{
CLOG
<<
i
<<
","
;
logs
<<
i
<<
","
;
}
CLOG
<<
" ]"
;
logs
<<
" ]"
;
}
CLOG
<<
"]"
<<
std
::
endl
;
logs
<<
"]"
<<
std
::
endl
;
}
}
...
...
@@ -93,25 +112,25 @@ struct Formater {
}
else
if
(
framework
::
IsType
<
const
bool
>
(
dtype
))
{
Display
<
bool
>
(
size
);
}
else
{
CLOG
<<
"
\t
data: unprintable type: "
<<
dtype
.
name
()
<<
std
::
endl
;
logs
<<
"
\t
data: unprintable type: "
<<
dtype
.
name
()
<<
std
::
endl
;
}
}
template
<
typename
T
>
void
Display
(
size_t
size
)
{
auto
*
d
=
reinterpret_cast
<
T
*>
(
data
);
CLOG
<<
"
\t
data: "
;
logs
<<
"
\t
data: "
;
if
(
summarize
!=
-
1
)
{
summarize
=
std
::
min
(
size
,
(
size_t
)
summarize
);
for
(
int
i
=
0
;
i
<
summarize
;
i
++
)
{
CLOG
<<
d
[
i
]
<<
","
;
logs
<<
d
[
i
]
<<
","
;
}
}
else
{
for
(
size_t
i
=
0
;
i
<
size
;
i
++
)
{
CLOG
<<
d
[
i
]
<<
","
;
logs
<<
d
[
i
]
<<
","
;
}
}
CLOG
<<
std
::
endl
;
logs
<<
std
::
endl
;
}
};
...
...
@@ -167,6 +186,7 @@ class TensorPrintOp : public framework::OperatorBase {
}
Formater
formater
;
formater
.
place
=
place
;
formater
.
message
=
Attr
<
std
::
string
>
(
"message"
);
if
(
Attr
<
bool
>
(
"print_tensor_name"
))
{
formater
.
name
=
printed_var_name
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录