Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
45a7cc62
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
45a7cc62
编写于
10月 12, 2019
作者:
Z
zhangxuefei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update img_cls.py
上级
80c18efc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
3 deletion
+23
-3
demo/autofinetune/img_cls.py
demo/autofinetune/img_cls.py
+23
-3
未找到文件。
demo/autofinetune/img_cls.py
浏览文件 @
45a7cc62
...
...
@@ -18,6 +18,11 @@ parser.add_argument(
help
=
"Whether use GPU for fine-tuning."
)
parser
.
add_argument
(
"--checkpoint_dir"
,
type
=
str
,
default
=
None
,
help
=
"Path to save log data."
)
parser
.
add_argument
(
"--module"
,
type
=
str
,
default
=
"mobilenet"
,
help
=
"Module used as feature extractor."
)
# the name of hyperparameters to be searched should keep with hparam.py
parser
.
add_argument
(
...
...
@@ -37,6 +42,15 @@ parser.add_argument(
parser
.
add_argument
(
"--model_path"
,
type
=
str
,
default
=
""
,
help
=
"load model path"
)
module_map
=
{
"resnet50"
:
"resnet_v2_50_imagenet"
,
"resnet101"
:
"resnet_v2_101_imagenet"
,
"resnet152"
:
"resnet_v2_152_imagenet"
,
"mobilenet"
:
"mobilenet_v2_imagenet"
,
"nasnet"
:
"nasnet_imagenet"
,
"pnasnet"
:
"pnasnet_imagenet"
}
def
is_path_valid
(
path
):
if
path
==
""
:
...
...
@@ -49,8 +63,9 @@ def is_path_valid(path):
def
finetune
(
args
):
# Load Paddlehub resnet50 pretrained model
module
=
hub
.
Module
(
name
=
"mobilenet_v2_imagenet"
)
# Load Paddlehub pretrained model, default as mobilenet
module
=
hub
.
Module
(
name
=
args
.
module
)
input_dict
,
output_dict
,
program
=
module
.
context
(
trainable
=
True
)
# Download dataset and use ImageClassificationReader to read dataset
...
...
@@ -61,6 +76,7 @@ def finetune(args):
images_mean
=
module
.
get_pretrained_images_mean
(),
images_std
=
module
.
get_pretrained_images_std
(),
dataset
=
dataset
)
# The last 2 layer of resnet_v2_101_imagenet network
feature_map
=
output_dict
[
"feature_map"
]
...
...
@@ -69,7 +85,6 @@ def finetune(args):
# Select finetune strategy, setup config and finetune
strategy
=
hub
.
DefaultFinetuneStrategy
(
learning_rate
=
args
.
learning_rate
)
config
=
hub
.
RunConfig
(
use_cuda
=
True
,
num_epoch
=
args
.
epochs
,
...
...
@@ -112,4 +127,9 @@ def finetune(args):
if
__name__
==
"__main__"
:
args
=
parser
.
parse_args
()
if
not
args
.
module
in
module_map
:
hub
.
logger
.
error
(
"module should in %s"
%
module_map
.
keys
())
exit
(
1
)
args
.
module
=
module_map
[
args
.
module
]
finetune
(
args
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录