Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
6d09f70a
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6d09f70a
编写于
3月 02, 2017
作者:
L
liaogang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add event_handler test and comment
上级
ec8e2108
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
20 addition
and
3 deletion
+20
-3
demo/image_classification/api_v2_train.py
demo/image_classification/api_v2_train.py
+20
-3
未找到文件。
demo/image_classification/api_v2_train.py
浏览文件 @
6d09f70a
...
@@ -12,27 +12,41 @@
...
@@ -12,27 +12,41 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License
# limitations under the License
import
sys
import
paddle.v2
as
paddle
from
api_v2_vgg
import
vgg_bn_drop
from
api_v2_vgg
import
vgg_bn_drop
from
api_v2_resnet
import
resnet_cifar10
from
api_v2_resnet
import
resnet_cifar10
import
paddle.v2
as
paddle
# End batch and end pass event handler
def
event_handler
(
event
):
def
event_handler
(
event
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
if
isinstance
(
event
,
paddle
.
event
.
EndIteration
):
if
event
.
batch_id
%
100
==
0
:
if
event
.
batch_id
%
100
==
0
:
print
"Pass %d, Batch %d, Cost %f"
%
(
event
.
pass_id
,
event
.
batch_id
,
print
"
\n
Pass %d, Batch %d, Cost %f, %s"
%
(
event
.
cost
)
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
,
event
.
metrics
)
else
:
sys
.
stdout
.
write
(
'.'
)
sys
.
stdout
.
flush
()
if
isinstance
(
event
,
paddle
.
event
.
EndPass
):
result
=
trainer
.
test
(
reader
=
paddle
.
reader
.
batched
(
paddle
.
dataset
.
cifar
.
test10
(),
batch_size
=
128
),
reader_dict
=
{
'image'
:
0
,
'label'
:
1
})
print
"
\n
Test with Pass %d, %s"
%
(
event
.
pass_id
,
result
.
metrics
)
def
main
():
def
main
():
datadim
=
3
*
32
*
32
datadim
=
3
*
32
*
32
classdim
=
10
classdim
=
10
# PaddlePaddle init
paddle
.
init
(
use_gpu
=
True
,
trainer_count
=
1
)
paddle
.
init
(
use_gpu
=
True
,
trainer_count
=
1
)
image
=
paddle
.
layer
.
data
(
image
=
paddle
.
layer
.
data
(
name
=
"image"
,
type
=
paddle
.
data_type
.
dense_vector
(
datadim
))
name
=
"image"
,
type
=
paddle
.
data_type
.
dense_vector
(
datadim
))
# Add neural network config
# option 1. resnet
# option 1. resnet
net
=
resnet_cifar10
(
image
,
depth
=
32
)
net
=
resnet_cifar10
(
image
,
depth
=
32
)
# option 2. vgg
# option 2. vgg
...
@@ -46,8 +60,10 @@ def main():
...
@@ -46,8 +60,10 @@ def main():
name
=
"label"
,
type
=
paddle
.
data_type
.
integer_value
(
classdim
))
name
=
"label"
,
type
=
paddle
.
data_type
.
integer_value
(
classdim
))
cost
=
paddle
.
layer
.
classification_cost
(
input
=
out
,
label
=
lbl
)
cost
=
paddle
.
layer
.
classification_cost
(
input
=
out
,
label
=
lbl
)
# Create parameters
parameters
=
paddle
.
parameters
.
create
(
cost
)
parameters
=
paddle
.
parameters
.
create
(
cost
)
# Create optimizer
momentum_optimizer
=
paddle
.
optimizer
.
Momentum
(
momentum_optimizer
=
paddle
.
optimizer
.
Momentum
(
momentum
=
0.9
,
momentum
=
0.9
,
regularization
=
paddle
.
optimizer
.
L2Regularization
(
rate
=
0.0002
*
128
),
regularization
=
paddle
.
optimizer
.
L2Regularization
(
rate
=
0.0002
*
128
),
...
@@ -57,6 +73,7 @@ def main():
...
@@ -57,6 +73,7 @@ def main():
learning_rate_schedule
=
'discexp'
,
learning_rate_schedule
=
'discexp'
,
batch_size
=
128
)
batch_size
=
128
)
# Create trainer
trainer
=
paddle
.
trainer
.
SGD
(
cost
=
cost
,
trainer
=
paddle
.
trainer
.
SGD
(
cost
=
cost
,
parameters
=
parameters
,
parameters
=
parameters
,
update_equation
=
momentum_optimizer
)
update_equation
=
momentum_optimizer
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录