Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
7534af80
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看板
未验证
提交
7534af80
编写于
3月 01, 2019
作者:
R
ruri
提交者:
GitHub
3月 01, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1810 from shippingwang/fix_run_script_bug
fix eval bug and refine run script
上级
a6fe23f7
8e42ab67
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
119 addition
and
45 deletion
+119
-45
fluid/PaddleCV/image_classification/README.md
fluid/PaddleCV/image_classification/README.md
+3
-1
fluid/PaddleCV/image_classification/README_cn.md
fluid/PaddleCV/image_classification/README_cn.md
+3
-1
fluid/PaddleCV/image_classification/eval.py
fluid/PaddleCV/image_classification/eval.py
+19
-8
fluid/PaddleCV/image_classification/infer.py
fluid/PaddleCV/image_classification/infer.py
+13
-3
fluid/PaddleCV/image_classification/run.sh
fluid/PaddleCV/image_classification/run.sh
+80
-31
fluid/PaddleCV/image_classification/train.py
fluid/PaddleCV/image_classification/train.py
+1
-1
未找到文件。
fluid/PaddleCV/image_classification/README.md
浏览文件 @
7534af80
...
...
@@ -81,7 +81,7 @@ python train.py \
*
**lr**
: initialized learning rate. Default: 0.1.
*
**pretrained_model**
: model path for pretraining. Default: None.
*
**checkpoint**
: the checkpoint path to resume. Default: None.
*
**model_category**
: the category of models, ("models"|"models_name"). Default: "models".
*
**model_category**
: the category of models, ("models"|"models_name"). Default: "models
_name
".
Or can start the training step by running the
```run.sh```
.
...
...
@@ -221,6 +221,8 @@ Models are trained by starting with learning rate ```0.1``` and decaying it by `
-
Released models: not specify parameter names
**NOTE: These are trained by using model_category=models**
|model | top-1/top-5 accuracy(PIL)| top-1/top-5 accuracy(CV2) |
|- |:-: |:-:|
|
[
ResNet152
](
http://paddle-imagenet-models.bj.bcebos.com/ResNet152_pretrained.zip
)
| 78.18%/93.93% | 78.11%/94.04% |
...
...
fluid/PaddleCV/image_classification/README_cn.md
浏览文件 @
7534af80
...
...
@@ -79,7 +79,7 @@ python train.py \
*
**lr**
: initialized learning rate. Default: 0.1.
*
**pretrained_model**
: model path for pretraining. Default: None.
*
**checkpoint**
: the checkpoint path to resume. Default: None.
*
**model_category**
: the category of models, ("models"|"models_name"). Default:"models".
*
**model_category**
: the category of models, ("models"|"models_name"). Default:"models
_name
".
**数据读取器说明:**
数据读取器定义在
```reader.py```
和
```reader_cv2.py```
中, 一般, CV2 reader可以提高数据读取速度, reader(PIL)可以得到相对更高的精度, 在
[
训练阶段
](
#training-a-model
)
, 默认采用的增广方式是随机裁剪与水平翻转, 而在
[
评估
](
#inference
)
与
[
推断
](
#inference
)
阶段用的默认方式是中心裁剪。当前支持的数据增广方式有:
*
旋转
...
...
@@ -213,6 +213,8 @@ Models包括两种模型:带有参数名字的模型,和不带有参数名
-
Released models: not specify parameter names
**注意:这是model_category = models 的预训练模型**
|model | top-1/top-5 accuracy(PIL)| top-1/top-5 accuracy(CV2) |
|- |:-: |:-:|
|
[
ResNet152
](
http://paddle-imagenet-models.bj.bcebos.com/ResNet152_pretrained.zip
)
| 78.18%/93.93% | 78.11%/94.04% |
...
...
fluid/PaddleCV/image_classification/eval.py
浏览文件 @
7534af80
...
...
@@ -7,8 +7,6 @@ import time
import
sys
import
paddle
import
paddle.fluid
as
fluid
#import models
import
models_name
as
models
#import reader_cv2 as reader
import
reader
as
reader
import
argparse
...
...
@@ -27,9 +25,20 @@ add_arg('image_shape', str, "3,224,224", "Input image size")
add_arg
(
'with_mem_opt'
,
bool
,
True
,
"Whether to use memory optimization or not."
)
add_arg
(
'pretrained_model'
,
str
,
None
,
"Whether to use pretrained model."
)
add_arg
(
'model'
,
str
,
"SE_ResNeXt50_32x4d"
,
"Set the network to use."
)
add_arg
(
'model_category'
,
str
,
"models_name"
,
"Whether to use models_name or not, valid value:'models','models_name'."
)
# yapf: enable
model_list
=
[
m
for
m
in
dir
(
models
)
if
"__"
not
in
m
]
def
set_models
(
model_category
):
global
models
assert
model_category
in
[
"models"
,
"models_name"
],
"{} is not in lists: {}"
.
format
(
model_category
,
[
"models"
,
"models_name"
])
if
model_category
==
"models_name"
:
import
models_name
as
models
else
:
import
models
as
models
def
eval
(
args
):
...
...
@@ -40,6 +49,7 @@ def eval(args):
with_memory_optimization
=
args
.
with_mem_opt
image_shape
=
[
int
(
m
)
for
m
in
args
.
image_shape
.
split
(
","
)]
model_list
=
[
m
for
m
in
dir
(
models
)
if
"__"
not
in
m
]
assert
model_name
in
model_list
,
"{} is not in lists: {}"
.
format
(
args
.
model
,
model_list
)
...
...
@@ -63,11 +73,11 @@ def eval(args):
acc_top5
=
fluid
.
layers
.
accuracy
(
input
=
out0
,
label
=
label
,
k
=
5
)
else
:
out
=
model
.
net
(
input
=
image
,
class_dim
=
class_dim
)
cost
=
fluid
.
layers
.
cross_entropy
(
input
=
out
,
label
=
label
)
cost
,
pred
=
fluid
.
layers
.
softmax_with_cross_entropy
(
out
,
label
,
return_softmax
=
True
)
avg_cost
=
fluid
.
layers
.
mean
(
x
=
cost
)
acc_top1
=
fluid
.
layers
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
1
)
acc_top5
=
fluid
.
layers
.
accuracy
(
input
=
out
,
label
=
label
,
k
=
5
)
acc_top1
=
fluid
.
layers
.
accuracy
(
input
=
pred
,
label
=
label
,
k
=
1
)
acc_top5
=
fluid
.
layers
.
accuracy
(
input
=
pred
,
label
=
label
,
k
=
5
)
test_program
=
fluid
.
default_main_program
().
clone
(
for_test
=
True
)
...
...
@@ -125,6 +135,7 @@ def eval(args):
def
main
():
args
=
parser
.
parse_args
()
print_arguments
(
args
)
set_models
(
args
.
model_category
)
eval
(
args
)
...
...
fluid/PaddleCV/image_classification/infer.py
浏览文件 @
7534af80
...
...
@@ -7,7 +7,6 @@ import time
import
sys
import
paddle
import
paddle.fluid
as
fluid
import
models
import
reader
import
argparse
import
functools
...
...
@@ -23,9 +22,19 @@ add_arg('image_shape', str, "3,224,224", "Input image size")
add_arg
(
'with_mem_opt'
,
bool
,
True
,
"Whether to use memory optimization or not."
)
add_arg
(
'pretrained_model'
,
str
,
None
,
"Whether to use pretrained model."
)
add_arg
(
'model'
,
str
,
"SE_ResNeXt50_32x4d"
,
"Set the network to use."
)
add_arg
(
'model_category'
,
str
,
"models_name"
,
"Whether to use models_name or not, valid value:'models','models_name'."
)
# yapf: enable
model_list
=
[
m
for
m
in
dir
(
models
)
if
"__"
not
in
m
]
def
set_models
(
model_category
):
global
models
assert
model_category
in
[
"models"
,
"models_name"
],
"{} is not in lists: {}"
.
format
(
model_category
,
[
"models"
,
"models_name"
])
if
model_category
==
"models_name"
:
import
models_name
as
models
else
:
import
models
as
models
def
infer
(
args
):
...
...
@@ -35,7 +44,7 @@ def infer(args):
pretrained_model
=
args
.
pretrained_model
with_memory_optimization
=
args
.
with_mem_opt
image_shape
=
[
int
(
m
)
for
m
in
args
.
image_shape
.
split
(
","
)]
model_list
=
[
m
for
m
in
dir
(
models
)
if
"__"
not
in
m
]
assert
model_name
in
model_list
,
"{} is not in lists: {}"
.
format
(
args
.
model
,
model_list
)
...
...
@@ -85,6 +94,7 @@ def infer(args):
def
main
():
args
=
parser
.
parse_args
()
print_arguments
(
args
)
set_models
(
args
.
model_category
)
infer
(
args
)
...
...
fluid/PaddleCV/image_classification/run.sh
浏览文件 @
7534af80
#Hyperparameters config
#Example: SE_ResNext50_32x4d
python train.py
\
--model
=
SE_ResNeXt50_32x4d
\
--batch_size
=
32
\
--batch_size
=
400
\
--total_images
=
1281167
\
--class_dim
=
1000
\
--image_shape
=
3,224,224
\
--model_save_dir
=
output/
\
--with_mem_opt
=
True
\
--lr_strategy
=
piecewise_decay
\
--lr
=
0.1
--lr_strategy
=
cosine_decay
\
--lr
=
0.1
\
--num_epochs
=
200
\
--l2_decay
=
1.2e-4
\
--model_category
=
models_name
\
# >log_SE_ResNeXt50_32x4d.txt 2>&1 &
#AlexNet:
#python train.py \
# --model=AlexNet \
...
...
@@ -20,23 +23,11 @@ python train.py \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --with_mem_opt=True \
# --model_category=models_name \
# --lr_strategy=piecewise_decay \
# --num_epochs=120 \
# --lr=0.01
#VGG11:
#python train.py \
# --model=VGG11 \
# --batch_size=512 \
# --total_images=1281167 \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --with_mem_opt=True \
# --lr_strategy=piecewise_decay \
# --num_epochs=120 \
# --lr=0.1
# --lr=0.01 \
# --l2_decay=1e-4
#MobileNet v1:
#python train.py \
...
...
@@ -47,9 +38,11 @@ python train.py \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --with_mem_opt=True \
# --model_category=models_name \
# --lr_strategy=piecewise_decay \
# --num_epochs=120 \
# --lr=0.1
# --lr=0.1 \
# --l2_decay=3e-5
#python train.py \
# --model=MobileNetV2 \
...
...
@@ -58,10 +51,12 @@ python train.py \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --model_category=models_name \
# --with_mem_opt=True \
# --lr_strategy=cosine_decay \
# --num_epochs=200 \
# --lr=0.1
# --num_epochs=240 \
# --lr=0.1 \
# --l2_decay=4e-5
#ResNet50:
#python train.py \
# --model=ResNet50 \
...
...
@@ -71,9 +66,11 @@ python train.py \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --with_mem_opt=True \
# --model_category=models_name \
# --lr_strategy=piecewise_decay \
# --num_epochs=120 \
# --lr=0.1
# --lr=0.1 \
# --l2_decay=1e-4
#ResNet101:
#python train.py \
...
...
@@ -83,44 +80,58 @@ python train.py \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --with_mem_opt=False \
# --model_category=models_name \
# --with_mem_opt=True \
# --lr_strategy=piecewise_decay \
# --num_epochs=120 \
# --lr=0.1
# --lr=0.1 \
# --l2_decay=1e-4
#ResNet152:
#python train.py \
# --model=ResNet152 \
# --batch_size=256 \
# --total_images=1281167 \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --model_save_dir=output/ \
# --lr_strategy=piecewise_decay \
# --model_category=models_name \
# --with_mem_opt=True \
# --lr=0.1 \
# --num_epochs=120 \
# --l2_decay=1e-4
#SE_ResNeXt50:
#SE_ResNeXt50
_32x4d
:
#python train.py \
# --model=SE_ResNeXt50 \
# --model=SE_ResNeXt50
_32x4d
\
# --batch_size=400 \
# --total_images=1281167 \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --lr_strategy=cosine_decay \
# --model_category=models_name \
# --model_save_dir=output/ \
# --lr=0.1 \
# --num_epochs=200 \
# --l2_decay=12e-5
# --with_mem_opt=True \
# --l2_decay=1.2e-4
#SE_ResNeXt101:
#SE_ResNeXt101
_32x4d
:
#python train.py \
# --model=SE_ResNeXt101 \
# --model=SE_ResNeXt101
_32x4d
\
# --batch_size=400 \
# --total_images=1281167 \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --lr_strategy=cosine_decay \
# --model_category=models_name \
# --model_save_dir=output/ \
# --lr=0.1 \
# --num_epochs=200 \
# --l2_decay=15e-5
# --with_mem_opt=True \
# --l2_decay=1.5e-5
#VGG11:
#python train.py \
...
...
@@ -129,8 +140,12 @@ python train.py \
# --total_images=1281167 \
# --image_shape=3,224,224 \
# --lr_strategy=cosine_decay \
# --class_dim=1000 \
# --model_category=models_name \
# --model_save_dir=output/ \
# --lr=0.1 \
# --num_epochs=90 \
# --with_mem_opt=True \
# --l2_decay=2e-4
#VGG13:
...
...
@@ -138,8 +153,42 @@ python train.py \
# --model=VGG13 \
# --batch_size=256 \
# --total_images=1281167 \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --lr_strategy=cosine_decay \
# --lr=0.01 \
# --num_epochs=90 \
# --model_category=models_name \
# --model_save_dir=output/ \
# --with_mem_opt=True \
# --l2_decay=3e-4
#VGG16:
#python train.py
# --model=VGG16 \
# --batch_size=256 \
# --total_images=1281167 \
# --class_dim=1000 \
# --lr_strategy=cosine_decay \
# --image_shape=3,224,224 \
# --model_category=models_name \
# --model_save_dir=output/ \
# --lr=0.01 \
# --num_epochs=90 \
# --with_mem_opt=True \
# --l2_decay=3e-4
#VGG19:
#python train.py
# --model=VGG19 \
# --batch_size=256 \
# --total_images=1281167 \
# --class_dim=1000 \
# --image_shape=3,224,224 \
# --lr_strategy=cosine_decay \
# --lr=0.01 \
# --num_epochs=90 \
# --with_mem_opt=True \
# --model_category=models_name \
# --model_save_dir=output/ \
# --l2_decay=3e-4
fluid/PaddleCV/image_classification/train.py
浏览文件 @
7534af80
...
...
@@ -39,7 +39,7 @@ add_arg('lr_strategy', str, "piecewise_decay", "Set the learning rate
add_arg
(
'model'
,
str
,
"SE_ResNeXt50_32x4d"
,
"Set the network to use."
)
add_arg
(
'enable_ce'
,
bool
,
False
,
"If set True, enable continuous evaluation job."
)
add_arg
(
'data_dir'
,
str
,
"./data/ILSVRC2012"
,
"The ImageNet dataset root dir."
)
add_arg
(
'model_category'
,
str
,
"models"
,
"Whether to use models_name or not, valid value:'models','models_name'."
)
add_arg
(
'model_category'
,
str
,
"models
_name
"
,
"Whether to use models_name or not, valid value:'models','models_name'."
)
add_arg
(
'fp16'
,
bool
,
False
,
"Enable half precision training with fp16."
)
add_arg
(
'scale_loss'
,
float
,
1.0
,
"Scale loss for fp16."
)
add_arg
(
'l2_decay'
,
float
,
1e-4
,
"L2_decay parameter."
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录