Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
334ad371
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
334ad371
编写于
6月 20, 2019
作者:
Z
zhaoyuchen2018
提交者:
GitHub
6月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Transform benchmark resnext50 changing to models (#2412)
This changing can improve performance test=develop
上级
83b367d7
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
45 addition
and
7 deletion
+45
-7
PaddleCV/image_classification/models/se_resnext.py
PaddleCV/image_classification/models/se_resnext.py
+15
-5
PaddleCV/image_classification/train.py
PaddleCV/image_classification/train.py
+30
-2
未找到文件。
PaddleCV/image_classification/models/se_resnext.py
浏览文件 @
334ad371
...
...
@@ -69,7 +69,8 @@ class SE_ResNeXt():
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
pool_type
=
'max'
)
pool_type
=
'max'
,
use_cudnn
=
False
)
elif
layers
==
101
:
cardinality
=
32
reduction_ratio
=
16
...
...
@@ -88,7 +89,8 @@ class SE_ResNeXt():
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
pool_type
=
'max'
)
pool_type
=
'max'
,
use_cudnn
=
False
)
elif
layers
==
152
:
cardinality
=
64
reduction_ratio
=
16
...
...
@@ -118,7 +120,7 @@ class SE_ResNeXt():
name
=
'conv3'
)
conv
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_size
=
3
,
pool_stride
=
2
,
pool_padding
=
1
,
\
pool_type
=
'max'
)
pool_type
=
'max'
,
use_cudnn
=
False
)
n
=
1
if
layers
==
50
or
layers
==
101
else
3
for
block
in
range
(
len
(
depth
)):
n
+=
1
...
...
@@ -132,7 +134,11 @@ class SE_ResNeXt():
name
=
str
(
n
)
+
'_'
+
str
(
i
+
1
))
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
input
=
conv
,
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
,
use_cudnn
=
False
)
drop
=
fluid
.
layers
.
dropout
(
x
=
pool
,
dropout_prob
=
0.5
,
seed
=
self
.
params
[
'dropout_seed'
])
stdv
=
1.0
/
math
.
sqrt
(
drop
.
shape
[
1
]
*
1.0
)
...
...
@@ -224,7 +230,11 @@ class SE_ResNeXt():
reduction_ratio
,
name
=
None
):
pool
=
fluid
.
layers
.
pool2d
(
input
=
input
,
pool_size
=
0
,
pool_type
=
'avg'
,
global_pooling
=
True
)
input
=
input
,
pool_size
=
0
,
pool_type
=
'avg'
,
global_pooling
=
True
,
use_cudnn
=
False
)
stdv
=
1.0
/
math
.
sqrt
(
pool
.
shape
[
1
]
*
1.0
)
squeeze
=
fluid
.
layers
.
fc
(
input
=
pool
,
...
...
PaddleCV/image_classification/train.py
浏览文件 @
334ad371
...
...
@@ -22,10 +22,23 @@ import time
import
sys
import
functools
import
math
def
set_paddle_flags
(
flags
):
for
key
,
value
in
flags
.
items
():
if
os
.
environ
.
get
(
key
,
None
)
is
None
:
os
.
environ
[
key
]
=
str
(
value
)
# NOTE(paddle-dev): All of these flags should be
# set before `import paddle`. Otherwise, it would
# not take any effect.
set_paddle_flags
({
'FLAGS_eager_delete_tensor_gb'
:
0
,
# enable gc
'FLAGS_fraction_of_gpu_memory_to_use'
:
0.98
})
import
argparse
import
functools
import
subprocess
import
paddle
import
paddle.fluid
as
fluid
import
paddle.dataset.flowers
as
flowers
...
...
@@ -50,6 +63,7 @@ add_arg('class_dim', int, 1000, "Class number.")
add_arg
(
'image_shape'
,
str
,
"3,224,224"
,
"input image size"
)
add_arg
(
'model_save_dir'
,
str
,
"output"
,
"model save directory"
)
add_arg
(
'with_mem_opt'
,
bool
,
True
,
"Whether to use memory optimization or not."
)
add_arg
(
'with_inplace'
,
bool
,
True
,
"Whether to use inplace memory optimization."
)
add_arg
(
'pretrained_model'
,
str
,
None
,
"Whether to use pretrained model."
)
add_arg
(
'checkpoint'
,
str
,
None
,
"Whether to resume checkpoint."
)
add_arg
(
'lr'
,
float
,
0.1
,
"set learning rate."
)
...
...
@@ -412,10 +426,20 @@ def train(args):
# use_ngraph is for CPU only, please refer to README_ngraph.md for details
use_ngraph
=
os
.
getenv
(
'FLAGS_use_ngraph'
)
if
not
use_ngraph
:
build_strategy
=
fluid
.
BuildStrategy
()
build_strategy
.
memory_optimize
=
args
.
with_mem_opt
build_strategy
.
enable_inplace
=
args
.
with_inplace
build_strategy
.
fuse_all_reduce_ops
=
1
exec_strategy
=
fluid
.
ExecutionStrategy
()
exec_strategy
.
num_iteration_per_drop_scope
=
10
train_exe
=
fluid
.
ParallelExecutor
(
main_program
=
train_prog
,
use_cuda
=
bool
(
args
.
use_gpu
),
loss_name
=
train_cost
.
name
)
loss_name
=
train_cost
.
name
,
build_strategy
=
build_strategy
,
exec_strategy
=
exec_strategy
)
else
:
train_exe
=
exe
...
...
@@ -429,6 +453,7 @@ def train(args):
test_info
=
[[],
[],
[]]
train_time
=
[]
batch_id
=
0
time_record
=
[]
try
:
while
True
:
t1
=
time
.
time
()
...
...
@@ -450,6 +475,7 @@ def train(args):
t2
=
time
.
time
()
period
=
t2
-
t1
time_record
.
append
(
period
)
loss
=
np
.
mean
(
np
.
array
(
loss
))
train_info
[
0
].
append
(
loss
)
...
...
@@ -457,6 +483,8 @@ def train(args):
train_time
.
append
(
period
)
if
batch_id
%
10
==
0
:
period
=
np
.
mean
(
time_record
)
time_record
=
[]
if
use_mixup
:
print
(
"Pass {0}, trainbatch {1}, loss {2}, lr {3}, time {4}"
.
format
(
pass_id
,
batch_id
,
"%.5f"
%
loss
,
"%.5f"
%
lr
,
"%2.2f sec"
%
period
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录