Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
0d2a35f1
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看板
未验证
提交
0d2a35f1
编写于
8月 25, 2018
作者:
G
guochaorong
提交者:
GitHub
8月 25, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1153 from qingqing01/ce_image_classification2
Update CE.
上级
ffbf5f7f
700da10d
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
77 addition
and
41 deletion
+77
-41
fluid/image_classification/.run_ce.sh
fluid/image_classification/.run_ce.sh
+3
-2
fluid/image_classification/_ce.py
fluid/image_classification/_ce.py
+6
-4
fluid/image_classification/eval.py
fluid/image_classification/eval.py
+3
-0
fluid/image_classification/infer.py
fluid/image_classification/infer.py
+3
-1
fluid/image_classification/models/alexnet.py
fluid/image_classification/models/alexnet.py
+3
-0
fluid/image_classification/models/dpn.py
fluid/image_classification/models/dpn.py
+7
-8
fluid/image_classification/models/googlenet.py
fluid/image_classification/models/googlenet.py
+4
-1
fluid/image_classification/models/inception_v4.py
fluid/image_classification/models/inception_v4.py
+3
-0
fluid/image_classification/models/learning_rate.py
fluid/image_classification/models/learning_rate.py
+3
-0
fluid/image_classification/models/mobilenet.py
fluid/image_classification/models/mobilenet.py
+3
-0
fluid/image_classification/models/resnet.py
fluid/image_classification/models/resnet.py
+4
-1
fluid/image_classification/models/se_resnext.py
fluid/image_classification/models/se_resnext.py
+11
-6
fluid/image_classification/models/vgg.py
fluid/image_classification/models/vgg.py
+3
-0
fluid/image_classification/train.py
fluid/image_classification/train.py
+19
-17
fluid/image_classification/utility.py
fluid/image_classification/utility.py
+2
-1
未找到文件。
fluid/image_classification/.run_ce.sh
浏览文件 @
0d2a35f1
#!/bin/bash
# This file is only used for continuous evaluation.
export
FLAGS_cudnn_deterministic
=
True
cudaid
=
${
object_detection_cudaid
:
=0
}
export
CUDA_VISIBLE_DEVICES
=
$cudaid
python train.py
--batch_size
=
64
--num_epochs
=
10
--total_images
=
6149
--enable_ce
=
True | python _ce.py
python train.py
--batch_size
=
64
--num_epochs
=
5
--enable_ce
=
True | python _ce.py
cudaid
=
${
object_detection_cudaid_m
:
=0, 1, 2, 3
}
export
CUDA_VISIBLE_DEVICES
=
$cudaid
python train.py
--batch_size
=
64
--num_epochs
=
10
--total_images
=
6149
--enable_ce
=
True | python _ce.py
python train.py
--batch_size
=
128
--num_epochs
=
5
--enable_ce
=
True | python _ce.py
fluid/image_classification/_ce.py
浏览文件 @
0d2a35f1
####this file is only used for continuous evaluation test!
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
sys
sys
.
path
.
append
(
os
.
environ
[
'ceroot'
])
...
...
@@ -14,7 +16,7 @@ train_cost_kpi = CostKpi('train_cost', 0.5, 0, actived=True, desc='train cost')
test_acc_top1_kpi
=
AccKpi
(
'test_acc_top1'
,
0.05
,
0
,
desc
=
'TOP1 ACC'
)
test_acc_top5_kpi
=
AccKpi
(
'test_acc_top5'
,
0.05
,
0
,
actived
=
False
,
desc
=
'TOP5 ACC'
)
test_cost_kpi
=
CostKpi
(
'test_cost'
,
1.0
,
0
,
actived
=
True
,
desc
=
'train cost'
)
test_cost_kpi
=
CostKpi
(
'test_cost'
,
0.05
,
0
,
actived
=
True
,
desc
=
'train cost'
)
train_speed_kpi
=
AccKpi
(
'train_speed'
,
0.5
,
...
...
@@ -27,13 +29,13 @@ train_acc_top1_card4_kpi = AccKpi(
train_acc_top5_card4_kpi
=
AccKpi
(
'train_acc_top5_card4'
,
0.05
,
0
,
actived
=
False
,
desc
=
'TOP5 ACC'
)
train_cost_card4_kpi
=
CostKpi
(
'train_cost_kpi'
,
0.
3
,
0
,
actived
=
True
,
desc
=
'train cost'
)
'train_cost_kpi'
,
0.
05
,
0
,
actived
=
True
,
desc
=
'train cost'
)
test_acc_top1_card4_kpi
=
AccKpi
(
'test_acc_top1_card4'
,
0.05
,
0
,
desc
=
'TOP1 ACC'
)
test_acc_top5_card4_kpi
=
AccKpi
(
'test_acc_top5_card4'
,
0.05
,
0
,
actived
=
False
,
desc
=
'TOP5 ACC'
)
test_cost_card4_kpi
=
CostKpi
(
'test_cost_card4'
,
1.0
,
0
,
actived
=
True
,
desc
=
'train cost'
)
'test_cost_card4'
,
0.05
,
0
,
actived
=
True
,
desc
=
'train cost'
)
train_speed_card4_kpi
=
AccKpi
(
'train_speed_card4'
,
0.5
,
...
...
fluid/image_classification/eval.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
numpy
as
np
import
time
...
...
fluid/image_classification/infer.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
numpy
as
np
import
time
...
...
@@ -15,7 +18,6 @@ import math
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
# yapf: disable
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
add_arg
(
'batch_size'
,
int
,
256
,
"Minibatch size."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU or not."
)
add_arg
(
'class_dim'
,
int
,
1000
,
"Class number."
)
add_arg
(
'image_shape'
,
str
,
"3,224,224"
,
"Input image size"
)
...
...
fluid/image_classification/models/alexnet.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
import
math
...
...
fluid/image_classification/models/dpn.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
numpy
as
np
import
time
import
sys
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.layers.control_flow
as
control_flow
import
paddle.fluid.layers.nn
as
nn
import
paddle.fluid.layers.tensor
as
tensor
import
math
import
paddle.fluid
as
fluid
__all__
=
[
"DPN"
,
"DPN68"
,
"DPN92"
,
"DPN98"
,
"DPN107"
,
"DPN131"
]
...
...
@@ -67,7 +66,7 @@ class DPN(object):
for
gc
in
range
(
4
):
bw
=
bws
[
gc
]
inc
=
inc_sec
[
gc
]
R
=
(
k_r
*
bw
)
/
rs
[
gc
]
R
=
(
k_r
*
bw
)
/
/
rs
[
gc
]
if
gc
==
0
:
_type1
=
'proj'
_type2
=
'normal'
...
...
@@ -178,8 +177,8 @@ class DPN(object):
_type
=
'normal'
):
kw
=
3
kh
=
3
pw
=
(
kw
-
1
)
/
2
ph
=
(
kh
-
1
)
/
2
pw
=
(
kw
-
1
)
/
/
2
ph
=
(
kh
-
1
)
/
/
2
# type
if
_type
is
'proj'
:
...
...
fluid/image_classification/models/googlenet.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
...
...
@@ -36,7 +39,7 @@ class GoogleNet():
num_filters
=
num_filters
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
(
filter_size
-
1
)
/
2
,
padding
=
(
filter_size
-
1
)
/
/
2
,
groups
=
groups
,
act
=
act
,
param_attr
=
param_attr
,
...
...
fluid/image_classification/models/inception_v4.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
import
math
...
...
fluid/image_classification/models/learning_rate.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.layers.ops
as
ops
...
...
fluid/image_classification/models/mobilenet.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle.fluid
as
fluid
from
paddle.fluid.initializer
import
MSRA
from
paddle.fluid.param_attr
import
ParamAttr
...
...
fluid/image_classification/models/resnet.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
import
math
...
...
@@ -75,7 +78,7 @@ class ResNet():
num_filters
=
num_filters
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
(
filter_size
-
1
)
/
2
,
padding
=
(
filter_size
-
1
)
/
/
2
,
groups
=
groups
,
act
=
None
,
bias_attr
=
False
)
...
...
fluid/image_classification/models/se_resnext.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
import
math
...
...
@@ -11,7 +14,7 @@ train_parameters = {
"input_size"
:
[
3
,
224
,
224
],
"input_mean"
:
[
0.485
,
0.456
,
0.406
],
"input_std"
:
[
0.229
,
0.224
,
0.225
],
"
dropout_seed"
:
Non
e
,
"
enable_ce"
:
Fals
e
,
"learning_strategy"
:
{
"name"
:
"piecewise_decay"
,
"batch_size"
:
256
,
...
...
@@ -102,9 +105,11 @@ class SE_ResNeXt():
pool
=
fluid
.
layers
.
pool2d
(
input
=
conv
,
pool_size
=
7
,
pool_type
=
'avg'
,
global_pooling
=
True
)
# do not set seed when traning, it is only used for debug
drop
=
fluid
.
layers
.
dropout
(
x
=
pool
,
dropout_prob
=
0.5
,
seed
=
self
.
params
[
"dropout_seed"
])
# enable_ce is used for continuous evaluation to remove the randomness
if
self
.
params
[
"enable_ce"
]:
drop
=
pool
else
:
drop
=
fluid
.
layers
.
dropout
(
x
=
pool
,
dropout_prob
=
0.5
)
stdv
=
1.0
/
math
.
sqrt
(
drop
.
shape
[
1
]
*
1.0
)
out
=
fluid
.
layers
.
fc
(
input
=
drop
,
size
=
class_dim
,
...
...
@@ -156,7 +161,7 @@ class SE_ResNeXt():
num_filters
=
num_filters
,
filter_size
=
filter_size
,
stride
=
stride
,
padding
=
(
filter_size
-
1
)
/
2
,
padding
=
(
filter_size
-
1
)
/
/
2
,
groups
=
groups
,
act
=
None
,
bias_attr
=
False
)
...
...
@@ -167,7 +172,7 @@ class SE_ResNeXt():
input
=
input
,
pool_size
=
0
,
pool_type
=
'avg'
,
global_pooling
=
True
)
stdv
=
1.0
/
math
.
sqrt
(
pool
.
shape
[
1
]
*
1.0
)
squeeze
=
fluid
.
layers
.
fc
(
input
=
pool
,
size
=
num_channels
/
reduction_ratio
,
size
=
num_channels
/
/
reduction_ratio
,
act
=
'relu'
,
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
Uniform
(
...
...
fluid/image_classification/models/vgg.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
paddle
import
paddle.fluid
as
fluid
...
...
fluid/image_classification/train.py
浏览文件 @
0d2a35f1
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
print_function
import
os
import
numpy
as
np
import
time
import
sys
import
functools
import
math
import
paddle
import
paddle.fluid
as
fluid
import
paddle.dataset.flowers
as
flowers
import
models
import
reader
import
argparse
import
functools
from
models.learning_rate
import
cosine_decay
from
utility
import
add_arguments
,
print_arguments
import
math
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
...
...
@@ -104,8 +107,11 @@ def train(args):
if
args
.
enable_ce
:
assert
model_name
==
"SE_ResNeXt50_32x4d"
fluid
.
default_startup_program
().
random_seed
=
1000
model
.
params
[
"enable_ce"
]
=
True
class_dim
=
102
if
model_name
is
"GoogleNet"
:
if
model_name
==
"GoogleNet"
:
out0
,
out1
,
out2
=
model
.
net
(
input
=
image
,
class_dim
=
class_dim
)
cost0
=
fluid
.
layers
.
cross_entropy
(
input
=
out0
,
label
=
label
)
cost1
=
fluid
.
layers
.
cross_entropy
(
input
=
out1
,
label
=
label
)
...
...
@@ -134,8 +140,6 @@ def train(args):
params
[
"num_epochs"
]
=
args
.
num_epochs
params
[
"learning_strategy"
][
"batch_size"
]
=
args
.
batch_size
params
[
"learning_strategy"
][
"name"
]
=
args
.
lr_strategy
if
args
.
enable_ce
:
params
[
"dropout_seed"
]
=
10
# initialize optimizer
optimizer
=
optimizer_setting
(
params
)
...
...
@@ -144,9 +148,6 @@ def train(args):
if
with_memory_optimization
:
fluid
.
memory_optimize
(
fluid
.
default_main_program
())
if
args
.
enable_ce
:
fluid
.
default_startup_program
().
random_seed
=
1000
place
=
fluid
.
CUDAPlace
(
0
)
if
args
.
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
exe
.
run
(
fluid
.
default_startup_program
())
...
...
@@ -172,6 +173,7 @@ def train(args):
# but it is time consuming. For faster speed, need another dataset.
import
random
random
.
seed
(
0
)
np
.
random
.
seed
(
0
)
train_reader
=
paddle
.
batch
(
flowers
.
train
(
use_xmap
=
False
),
batch_size
=
train_batch_size
)
test_reader
=
paddle
.
batch
(
...
...
@@ -256,7 +258,7 @@ def train(args):
# This is for continuous evaluation only
if
args
.
enable_ce
and
pass_id
==
args
.
num_epochs
-
1
:
if
gpu_nums
==
1
:
# Use the
last
cost/acc for training
# Use the
mean
cost/acc for training
print
(
"kpis train_cost %s"
%
train_loss
)
print
(
"kpis train_acc_top1 %s"
%
train_acc1
)
print
(
"kpis train_acc_top5 %s"
%
train_acc5
)
...
...
@@ -266,21 +268,21 @@ def train(args):
print
(
"kpis test_acc_top5 %s"
%
test_acc5
)
print
(
"kpis train_speed %s"
%
train_speed
)
else
:
# Use the
last
cost/acc for training
print
(
"kpis
train_cost_card%s
%s"
%
# Use the
mean
cost/acc for training
print
(
"kpis
train_cost_card%s
%s"
%
(
gpu_nums
,
train_loss
))
print
(
"kpis
train_acc_top1_card%s
%s"
%
print
(
"kpis
train_acc_top1_card%s
%s"
%
(
gpu_nums
,
train_acc1
))
print
(
"kpis
train_acc_top5_card%s
%s"
%
print
(
"kpis
train_acc_top5_card%s
%s"
%
(
gpu_nums
,
train_acc5
))
# Use the mean cost/acc for testing
print
(
"kpis
test_cost_card%s
%s"
%
print
(
"kpis
test_cost_card%s
%s"
%
(
gpu_nums
,
test_loss
))
print
(
"kpis
test_acc_top1_card%s
%s"
%
print
(
"kpis
test_acc_top1_card%s
%s"
%
(
gpu_nums
,
test_acc1
))
print
(
"kpis
test_acc_top5_card%s
%s"
%
print
(
"kpis
test_acc_top5_card%s
%s"
%
(
gpu_nums
,
test_acc5
))
print
(
"kpis
train_speed_card%s
%s"
%
print
(
"kpis
train_speed_card%s
%s"
%
(
gpu_nums
,
train_speed
))
...
...
fluid/image_classification/utility.py
浏览文件 @
0d2a35f1
...
...
@@ -18,6 +18,7 @@ from __future__ import division
from
__future__
import
print_function
import
distutils.util
import
numpy
as
np
import
six
from
paddle.fluid
import
core
...
...
@@ -37,7 +38,7 @@ def print_arguments(args):
:type args: argparse.Namespace
"""
print
(
"----------- Configuration Arguments -----------"
)
for
arg
,
value
in
sorted
(
vars
(
args
).
iteritems
(
)):
for
arg
,
value
in
sorted
(
six
.
iteritems
(
vars
(
args
)
)):
print
(
"%s: %s"
%
(
arg
,
value
))
print
(
"------------------------------------------------"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录