Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
65e1a0a8
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
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看板
提交
65e1a0a8
编写于
1月 16, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add demo script
上级
de93df86
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
39 addition
and
10 deletion
+39
-10
example/image-classification/create_module.sh
example/image-classification/create_module.sh
+25
-0
example/image-classification/train.py
example/image-classification/train.py
+14
-10
未找到文件。
example/image-classification/create_module.sh
0 → 100644
浏览文件 @
65e1a0a8
#!/bin/bash
set
-o
nounset
set
-o
errexit
script_path
=
$(
cd
`
dirname
$0
`
;
pwd
)
cd
$script_path
model_name
=
"ResNet50"
hub_module_save_dir
=
"./hub_module"
while
getopts
"m:d:"
options
do
case
"
$options
"
in
d
)
hub_module_save_dir
=
$OPTARG
;;
m
)
model_name
=
$OPTARG
;;
?
)
echo
"unknown options"
exit
1
;;
esac
done
sh pretraind_models/download_model.sh
${
model_name
}
python train.py
--create_module
=
True
--pretrained_model
=
pretraind_models/
${
model_name
}
--model
${
model_name
}
--use_gpu
=
False
example/image-classification/train.py
浏览文件 @
65e1a0a8
...
...
@@ -23,6 +23,7 @@ from utility import add_arguments, print_arguments
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
)
add_arg
=
functools
.
partial
(
add_arguments
,
argparser
=
parser
)
# yapf: disable
add_arg
(
'create_module'
,
bool
,
False
,
"create a hub module or not"
)
add_arg
(
'batch_size'
,
int
,
32
,
"Minibatch size."
)
add_arg
(
'use_gpu'
,
bool
,
True
,
"Whether to use GPU or not."
)
add_arg
(
'total_images'
,
int
,
12000
,
"Training image number."
)
...
...
@@ -201,6 +202,19 @@ def train(args):
fluid
.
io
.
load_vars
(
exe
,
pretrained_model
,
main_program
=
train_prog
,
predicate
=
if_exist
)
if
args
.
create_module
:
assert
pretrained_model
,
"need a pretrained module to create a hub module"
sign1
=
hub
.
create_signature
(
"classification"
,
inputs
=
[
image
],
outputs
=
[
predition
])
sign2
=
hub
.
create_signature
(
"feature_map"
,
inputs
=
[
image
],
outputs
=
[
feature_map
])
sign3
=
hub
.
create_signature
(
inputs
=
[
image
],
outputs
=
[
predition
])
hub
.
create_module
(
sign_arr
=
[
sign1
,
sign2
,
sign3
],
program
=
train_prog
,
module_dir
=
"hub_module_"
+
args
.
model
)
exit
()
visible_device
=
os
.
getenv
(
'CUDA_VISIBLE_DEVICES'
)
if
visible_device
:
device_num
=
len
(
visible_device
.
split
(
','
))
...
...
@@ -296,16 +310,6 @@ def train(args):
os
.
makedirs
(
model_path
)
fluid
.
io
.
save_persistables
(
exe
,
model_path
,
main_program
=
train_prog
)
sign1
=
hub
.
create_signature
(
"classification"
,
inputs
=
[
image
],
outputs
=
[
predition
])
sign2
=
hub
.
create_signature
(
"feature_map"
,
inputs
=
[
image
],
outputs
=
[
feature_map
])
sign3
=
hub
.
create_signature
(
inputs
=
[
image
],
outputs
=
[
predition
])
hub
.
create_module
(
sign_arr
=
[
sign1
,
sign2
,
sign3
],
program
=
train_prog
,
module_dir
=
"hub_module"
+
args
.
model
)
def
main
():
args
=
parser
.
parse_args
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录