Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
5a685841
P
Paddle
项目概览
夏有凉风,冬有雪
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5a685841
编写于
12月 22, 2016
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test on GPU
上级
65e957ca
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
11 deletion
+8
-11
demo/mnist/api_train.py
demo/mnist/api_train.py
+7
-10
paddle/api/Vector.cpp
paddle/api/Vector.cpp
+1
-1
未找到文件。
demo/mnist/api_train.py
浏览文件 @
5a685841
...
...
@@ -53,7 +53,7 @@ def input_order_converter(generator):
def
main
():
api
.
initPaddle
(
"-use_gpu=
tru
e"
,
"-trainer_count=4"
)
# use 4 cpu cores
api
.
initPaddle
(
"-use_gpu=
fals
e"
,
"-trainer_count=4"
)
# use 4 cpu cores
config
=
paddle
.
trainer
.
config_parser
.
parse_config
(
'simple_mnist_network.py'
,
''
)
...
...
@@ -106,7 +106,7 @@ def main():
# TrainData will stored in a data pool. Currently implementation is not care
# about memory, speed. Just a very naive implementation.
train_data_generator
=
input_order_converter
(
read_from_mnist
(
train_file
))
train_data
=
BatchPool
(
train_data_generator
,
128
)
train_data
=
BatchPool
(
train_data_generator
,
512
)
# outArgs is Neural Network forward result. Here is not useful, just passed
# to gradient_machine.forward
...
...
@@ -126,16 +126,13 @@ def main():
# batch_evaluator can be used between start/finish.
batch_evaluator
.
start
()
# A callback when backward.
# It is used for updating weight values vy calculated Gradient.
def
updater_callback
(
param
):
updater
.
update
(
param
)
# forwardBackward is a shortcut for forward and backward.
# It is sometimes faster than invoke forward/backward separately,
# because in GradientMachine, it may be async.
m
.
forwardBackward
(
converter
(
data_batch
),
outArgs
,
pass_type
,
updater_callback
)
m
.
forwardBackward
(
converter
(
data_batch
),
outArgs
,
pass_type
)
for
each_param
in
m
.
getParameters
():
updater
.
update
(
each_param
)
# Get cost. We use numpy to calculate total cost for this batch.
cost_vec
=
outArgs
.
getSlotValue
(
0
)
...
...
@@ -159,7 +156,7 @@ def main():
updater
.
apply
()
test_evaluator
.
start
()
test_data_generator
=
input_order_converter
(
read_from_mnist
(
test_file
))
for
data_batch
in
generator_to_batch
(
test_data_generator
,
128
):
for
data_batch
in
generator_to_batch
(
test_data_generator
,
512
):
# in testing stage, only forward is needed.
m
.
forward
(
converter
(
data_batch
),
outArgs
,
api
.
PASS_TEST
)
m
.
eval
(
test_evaluator
)
...
...
paddle/api/Vector.cpp
浏览文件 @
5a685841
...
...
@@ -253,7 +253,7 @@ void Vector::copyToNumpyArray(float** view_m_data, int* dim1) {
*
view_m_data
=
new
float
[
*
dim1
];
if
(
auto
cpuVec
=
dynamic_cast
<
paddle
::
CpuVector
*>
(
m
->
vec
.
get
()))
{
std
::
memcpy
(
*
view_m_data
,
cpuVec
->
getData
(),
sizeof
(
float
)
*
(
*
dim1
));
}
else
if
(
auto
gpuVec
=
dynamic_cast
<
paddle
::
C
puVector
*>
(
m
->
vec
.
get
()))
{
}
else
if
(
auto
gpuVec
=
dynamic_cast
<
paddle
::
G
puVector
*>
(
m
->
vec
.
get
()))
{
hl_memcpy_device2host
(
*
view_m_data
,
gpuVec
->
getData
(),
sizeof
(
float
)
*
(
*
dim1
));
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录