Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
432638d1
B
book
项目概览
PaddlePaddle
/
book
通知
16
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
432638d1
编写于
8月 17, 2018
作者:
C
Chen Weihang
提交者:
GitHub
8月 17, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #597 from JiabinYang/book01_refine
fix representation problem in train.py
上级
d17f2d2a
6bdf66e0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
6 deletion
+18
-6
01.fit_a_line/train.py
01.fit_a_line/train.py
+18
-6
未找到文件。
01.fit_a_line/train.py
浏览文件 @
432638d1
...
...
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
import
numpy
...
...
@@ -53,7 +54,7 @@ trainer = fluid.Trainer(
feed_order
=
[
'x'
,
'y'
]
# Specify the directory
path
to save the parameters
# Specify the directory to save the parameters
params_dirname
=
"fit_a_line.inference.model"
# Plot data
...
...
@@ -65,11 +66,11 @@ plot_cost = Ploter(train_title, test_title)
step
=
0
#
event_handler to print
training and testing info
#
event_handler prints
training and testing info
def
event_handler_plot
(
event
):
global
step
if
isinstance
(
event
,
fluid
.
EndStepEvent
):
if
event
.
step
%
10
==
0
:
#
every 10 batches, record a test cost
if
event
.
step
%
10
==
0
:
#
record the test cost every 10 seconds
test_metrics
=
trainer
.
test
(
reader
=
test_reader
,
feed_order
=
feed_order
)
...
...
@@ -106,7 +107,18 @@ inferencer = fluid.Inferencer(
infer_func
=
inference_program
,
param_path
=
params_dirname
,
place
=
place
)
batch_size
=
10
tensor_x
=
numpy
.
random
.
uniform
(
0
,
10
,
[
batch_size
,
13
]).
astype
(
"float32"
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
uci_housing
.
test
(),
batch_size
=
batch_size
)
test_data
=
test_reader
().
next
()
test_feat
=
numpy
.
array
([
data
[
0
]
for
data
in
test_data
]).
astype
(
"float32"
)
test_label
=
numpy
.
array
([
data
[
1
]
for
data
in
test_data
]).
astype
(
"float32"
)
results
=
inferencer
.
infer
({
'x'
:
test_feat
})
print
(
"infer results: (House Price)"
)
for
k
in
range
(
0
,
batch_size
-
1
):
print
(
"%d. %f"
%
(
k
,
results
[
0
][
k
]))
results
=
inferencer
.
infer
({
'x'
:
tensor_x
})
print
(
"infer results: "
,
results
[
0
])
print
(
"
\n
ground truth:"
)
for
k
in
range
(
0
,
batch_size
-
1
):
print
(
"%d. %f"
%
(
k
,
test_label
[
k
]))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录