Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
b80f73b1
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b80f73b1
编写于
9月 25, 2020
作者:
L
LielinJiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add visualdl callback
上级
827ac36f
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
141 addition
and
4 deletion
+141
-4
paddle/scripts/paddle_build.sh
paddle/scripts/paddle_build.sh
+4
-4
python/paddle/hapi/callbacks.py
python/paddle/hapi/callbacks.py
+109
-0
python/paddle/tests/test_callbacks.py
python/paddle/tests/test_callbacks.py
+28
-0
未找到文件。
paddle/scripts/paddle_build.sh
浏览文件 @
b80f73b1
...
@@ -1348,7 +1348,7 @@ EOF
...
@@ -1348,7 +1348,7 @@ EOF
# run paddle version to install python packages first
# run paddle version to install python packages first
RUN apt-get update &&
${
NCCL_DEPS
}
RUN apt-get update &&
${
NCCL_DEPS
}
RUN apt-get install -y wget python3 python3-pip libgtk2.0-dev dmidecode python3-tk &&
\
RUN apt-get install -y wget python3 python3-pip libgtk2.0-dev dmidecode python3-tk &&
\
pip3 install opencv-python py-cpuinfo==5.0.0 && wget
${
ref_web
}
/
${
ref_paddle35
}
&&
${
ref_paddle35_mv1
}
pip3 install
${
ref_paddle35_whl
}
${
ref_paddle35_mv2
}
; apt-get install -f -y &&
\
pip3 install opencv-python
visualdl
py-cpuinfo==5.0.0 && wget
${
ref_web
}
/
${
ref_paddle35
}
&&
${
ref_paddle35_mv1
}
pip3 install
${
ref_paddle35_whl
}
${
ref_paddle35_mv2
}
; apt-get install -f -y &&
\
apt-get clean -y &&
\
apt-get clean -y &&
\
rm -f
${
ref_paddle35
}
&&
\
rm -f
${
ref_paddle35
}
&&
\
ldconfig
ldconfig
...
@@ -1370,7 +1370,7 @@ EOF
...
@@ -1370,7 +1370,7 @@ EOF
CFLAGS="-Wformat" ./configure --prefix=/usr/local/ --enable-shared > /dev/null &&
\
CFLAGS="-Wformat" ./configure --prefix=/usr/local/ --enable-shared > /dev/null &&
\
make -j8 > /dev/null && make altinstall > /dev/null && cd ../ && rm Python-3.6.0.tgz
make -j8 > /dev/null && make altinstall > /dev/null && cd ../ && rm Python-3.6.0.tgz
RUN apt-get install -y libgtk2.0-dev dmidecode python3-tk && ldconfig &&
\
RUN apt-get install -y libgtk2.0-dev dmidecode python3-tk && ldconfig &&
\
pip3.6 install opencv-python && wget
${
ref_web
}
/
${
ref_paddle36
}
&&
${
ref_paddle36_mv1
}
pip3.6 install
${
ref_paddle36_whl
}
${
ref_paddle36_mv2
}
; apt-get install -f -y &&
\
pip3.6 install opencv-python
visualdl
&& wget
${
ref_web
}
/
${
ref_paddle36
}
&&
${
ref_paddle36_mv1
}
pip3.6 install
${
ref_paddle36_whl
}
${
ref_paddle36_mv2
}
; apt-get install -f -y &&
\
apt-get clean -y &&
\
apt-get clean -y &&
\
rm -f
${
ref_paddle36
}
&&
\
rm -f
${
ref_paddle36
}
&&
\
ldconfig
ldconfig
...
@@ -1386,7 +1386,7 @@ EOF
...
@@ -1386,7 +1386,7 @@ EOF
CFLAGS="-Wformat" ./configure --prefix=/usr/local/ --enable-shared > /dev/null &&
\
CFLAGS="-Wformat" ./configure --prefix=/usr/local/ --enable-shared > /dev/null &&
\
make -j8 > /dev/null && make altinstall > /dev/null && cd ../ && rm Python-3.7.0.tgz
make -j8 > /dev/null && make altinstall > /dev/null && cd ../ && rm Python-3.7.0.tgz
RUN apt-get install -y libgtk2.0-dev dmidecode python3-tk && ldconfig &&
\
RUN apt-get install -y libgtk2.0-dev dmidecode python3-tk && ldconfig &&
\
pip3.7 install opencv-python && wget
${
ref_web
}
/
${
ref_paddle37
}
&& pip3.7 install
${
ref_paddle37_whl
}
; apt-get install -f -y &&
\
pip3.7 install opencv-python
visualdl
&& wget
${
ref_web
}
/
${
ref_paddle37
}
&& pip3.7 install
${
ref_paddle37_whl
}
; apt-get install -f -y &&
\
apt-get clean -y &&
\
apt-get clean -y &&
\
rm -f
${
ref_paddle37
}
&&
\
rm -f
${
ref_paddle37
}
&&
\
ldconfig
ldconfig
...
@@ -1402,7 +1402,7 @@ EOF
...
@@ -1402,7 +1402,7 @@ EOF
CFLAGS="-Wformat" ./configure --prefix=/usr/local/ --enable-shared > /dev/null &&
\
CFLAGS="-Wformat" ./configure --prefix=/usr/local/ --enable-shared > /dev/null &&
\
make -j8 > /dev/null && make altinstall > /dev/null && cd ../ && rm Python-3.8.0.tgz
make -j8 > /dev/null && make altinstall > /dev/null && cd ../ && rm Python-3.8.0.tgz
RUN apt-get install -y libgtk2.0-dev dmidecode python3-tk && ldconfig &&
\
RUN apt-get install -y libgtk2.0-dev dmidecode python3-tk && ldconfig &&
\
pip3.8 install opencv-python && wget
${
ref_web
}
/
${
ref_paddle38
}
&& pip3.8 install
${
ref_paddle38_whl
}
; apt-get install -f -y &&
\
pip3.8 install opencv-python
visualdl
&& wget
${
ref_web
}
/
${
ref_paddle38
}
&& pip3.8 install
${
ref_paddle38_whl
}
; apt-get install -f -y &&
\
apt-get clean -y &&
\
apt-get clean -y &&
\
rm -f
${
ref_paddle38
}
&&
\
rm -f
${
ref_paddle38
}
&&
\
ldconfig
ldconfig
...
...
python/paddle/hapi/callbacks.py
浏览文件 @
b80f73b1
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
import
os
import
os
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.fluid.dygraph.parallel
import
ParallelEnv
from
paddle.utils
import
try_import
from
.progressbar
import
ProgressBar
from
.progressbar
import
ProgressBar
...
@@ -469,3 +470,111 @@ class ModelCheckpoint(Callback):
...
@@ -469,3 +470,111 @@ class ModelCheckpoint(Callback):
path
=
'{}/final'
.
format
(
self
.
save_dir
)
path
=
'{}/final'
.
format
(
self
.
save_dir
)
print
(
'save checkpoint at {}'
.
format
(
os
.
path
.
abspath
(
path
)))
print
(
'save checkpoint at {}'
.
format
(
os
.
path
.
abspath
(
path
)))
self
.
model
.
save
(
path
)
self
.
model
.
save
(
path
)
class
VisualDL
(
Callback
):
"""VisualDL callback function
Args:
log_dir (str): The directory to save visualdl log file.
Examples:
.. code-block:: python
import paddle
from paddle.static import InputSpec
inputs = [InputSpec([-1, 1, 28, 28], 'float32', 'image')]
labels = [InputSpec([None, 1], 'int64', 'label')]
train_dataset = paddle.vision.datasets.MNIST(mode='train')
eval_dataset = paddle.vision.datasets.MNIST(mode='test')
net = paddle.vision.LeNet()
model = paddle.Model(net, inputs, labels)
optim = paddle.optimizer.Adam(0.001, parameters=net.parameters())
model.prepare(optimizer=optim,
loss=paddle.nn.CrossEntropyLoss(),
metrics=paddle.metric.Accuracy())
callback = paddle.callbacks.VisualDL(log_dir='visualdl_log_dir')
model.fit(train_dataset, eval_dataset, batch_size=64, callbacks=callback)
"""
def
__init__
(
self
,
log_dir
):
self
.
log_dir
=
log_dir
self
.
epochs
=
None
self
.
steps
=
None
def
_is_write
(
self
):
return
ParallelEnv
().
local_rank
==
0
def
on_train_begin
(
self
,
logs
=
None
):
self
.
epochs
=
self
.
params
[
'epochs'
]
assert
self
.
epochs
self
.
train_metrics
=
self
.
params
[
'metrics'
]
assert
self
.
train_metrics
self
.
_is_fit
=
True
def
on_epoch_begin
(
self
,
epoch
=
None
,
logs
=
None
):
visualdl
=
try_import
(
'visualdl'
)
self
.
steps
=
self
.
params
[
'steps'
]
self
.
epoch
=
epoch
self
.
train_step
=
0
self
.
train_writer
=
visualdl
.
LogWriter
(
self
.
log_dir
)
def
_updates
(
self
,
logs
,
mode
):
metrics
=
getattr
(
self
,
'%s_metrics'
%
(
mode
))
writer
=
getattr
(
self
,
'%s_writer'
%
(
mode
))
current_step
=
getattr
(
self
,
'%s_step'
%
(
mode
))
if
mode
==
'train'
:
total_step
=
self
.
epoch
*
self
.
steps
+
current_step
else
:
total_step
=
self
.
epoch
for
k
in
metrics
:
if
k
in
logs
:
temp_tag
=
mode
+
'/'
+
k
if
isinstance
(
logs
[
k
],
(
list
,
tuple
)):
temp_value
=
logs
[
k
][
0
]
elif
isinstance
(
logs
[
k
],
numbers
.
Number
):
temp_value
=
logs
[
k
]
else
:
continue
writer
.
add_scalar
(
tag
=
temp_tag
,
step
=
total_step
,
value
=
temp_value
)
def
on_train_batch_end
(
self
,
step
,
logs
=
None
):
logs
=
logs
or
{}
self
.
train_step
+=
1
if
self
.
_is_write
():
if
self
.
steps
is
None
or
self
.
train_step
<
self
.
steps
:
self
.
_updates
(
logs
,
'train'
)
def
on_epoch_end
(
self
,
epoch
,
logs
=
None
):
logs
=
logs
or
{}
if
self
.
_is_write
()
and
(
self
.
steps
is
not
None
):
self
.
_updates
(
logs
,
'train'
)
def
on_eval_begin
(
self
,
logs
=
None
):
visualdl
=
try_import
(
'visualdl'
)
self
.
eval_steps
=
logs
.
get
(
'steps'
,
None
)
self
.
eval_metrics
=
logs
.
get
(
'metrics'
,
[])
self
.
eval_step
=
0
self
.
evaled_samples
=
0
self
.
eval_writer
=
visualdl
.
LogWriter
(
self
.
log_dir
)
def
on_train_end
(
self
,
logs
=
None
):
if
hasattr
(
self
,
'train_writer'
):
self
.
train_writer
.
close
()
if
hasattr
(
self
,
'eval_writer'
):
self
.
eval_writer
.
close
()
def
on_eval_end
(
self
,
logs
=
None
):
self
.
_updates
(
logs
,
'eval'
)
if
(
not
hasattr
(
self
,
'_is_fit'
))
and
hasattr
(
self
,
'eval_writer'
):
self
.
eval_writer
.
close
()
python/paddle/tests/test_callbacks.py
浏览文件 @
b80f73b1
...
@@ -17,6 +17,7 @@ import time
...
@@ -17,6 +17,7 @@ import time
import
random
import
random
import
tempfile
import
tempfile
import
shutil
import
shutil
import
paddle
from
paddle
import
Model
from
paddle
import
Model
from
paddle.static
import
InputSpec
from
paddle.static
import
InputSpec
...
@@ -102,6 +103,33 @@ class TestCallbacks(unittest.TestCase):
...
@@ -102,6 +103,33 @@ class TestCallbacks(unittest.TestCase):
self
.
verbose
=
2
self
.
verbose
=
2
self
.
run_callback
()
self
.
run_callback
()
def
test_visualdl_callback
(
self
):
try
:
import
visualdl
except
:
return
inputs
=
[
InputSpec
([
-
1
,
1
,
28
,
28
],
'float32'
,
'image'
)]
labels
=
[
InputSpec
([
None
,
1
],
'int64'
,
'label'
)]
train_dataset
=
paddle
.
vision
.
datasets
.
MNIST
(
mode
=
'train'
)
eval_dataset
=
paddle
.
vision
.
datasets
.
MNIST
(
mode
=
'test'
)
net
=
paddle
.
vision
.
LeNet
()
model
=
paddle
.
Model
(
net
,
inputs
,
labels
)
optim
=
paddle
.
optimizer
.
Adam
(
0.001
,
parameters
=
net
.
parameters
())
model
.
prepare
(
optimizer
=
optim
,
loss
=
paddle
.
nn
.
CrossEntropyLoss
(),
metrics
=
paddle
.
metric
.
Accuracy
())
callback
=
paddle
.
callbacks
.
VisualDL
(
log_dir
=
'visualdl_log_dir'
)
model
.
fit
(
train_dataset
,
eval_dataset
,
batch_size
=
64
,
callbacks
=
callback
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录