Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
5ff5415f
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看板
提交
5ff5415f
编写于
4月 16, 2019
作者:
S
Steffy-zxf
提交者:
wuzewu
4月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the bug that user can't download the modules (#5)
* Fix the bug that user can't download the modules
上级
44a9c1ab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
18 deletion
+40
-18
paddlehub/commands/download.py
paddlehub/commands/download.py
+31
-17
paddlehub/commands/run.py
paddlehub/commands/run.py
+9
-1
未找到文件。
paddlehub/commands/download.py
浏览文件 @
5ff5415f
...
@@ -31,40 +31,44 @@ class DownloadCommand(BaseCommand):
...
@@ -31,40 +31,44 @@ class DownloadCommand(BaseCommand):
def
__init__
(
self
,
name
):
def
__init__
(
self
,
name
):
super
(
DownloadCommand
,
self
).
__init__
(
name
)
super
(
DownloadCommand
,
self
).
__init__
(
name
)
self
.
show_in_help
=
True
self
.
show_in_help
=
True
self
.
description
=
"Download PaddlePaddle pretrained model files."
self
.
description
=
"Download PaddlePaddle pretrained model
/module
files."
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
self
.
parser
=
self
.
parser
=
argparse
.
ArgumentParser
(
description
=
self
.
__class__
.
__doc__
,
description
=
self
.
__class__
.
__doc__
,
prog
=
'%s %s <model_name>'
%
(
ENTRY
,
name
),
prog
=
'%s %s <model_name
/module_name
>'
%
(
ENTRY
,
name
),
usage
=
'%(prog)s [options]'
,
usage
=
'%(prog)s [options]'
,
add_help
=
False
)
add_help
=
False
)
# yapf: disable
# yapf: disable
self
.
add_arg
(
'--output_path'
,
str
,
"."
,
"path to save the model"
)
self
.
add_arg
(
"--type"
,
str
,
"All"
,
"choice: Module/Model/All"
)
self
.
add_arg
(
'--output_path'
,
str
,
"."
,
"path to save the model/module"
)
self
.
add_arg
(
'--uncompress'
,
bool
,
False
,
"uncompress the download package or not"
)
self
.
add_arg
(
'--uncompress'
,
bool
,
False
,
"uncompress the download package or not"
)
# yapf: enable
# yapf: enable
def
exec
(
self
,
argv
):
def
exec
(
self
,
argv
):
if
not
argv
:
if
not
argv
:
print
(
"ERROR: Please provide the model name
\n
"
)
print
(
"ERROR: Please provide the model
/module
name
\n
"
)
self
.
help
()
self
.
help
()
return
False
return
False
model_name
=
argv
[
0
]
mod_name
=
argv
[
0
]
model_version
=
None
if
"=="
not
in
model_name
else
model_name
.
split
(
mod_version
=
None
if
"=="
not
in
mod_name
else
mod_name
.
split
(
"=="
)[
1
]
"=="
)[
1
]
mod_name
=
mod_name
if
"=="
not
in
mod_name
else
mod_name
.
split
(
"=="
)[
0
]
model_name
=
model_name
if
"=="
not
in
model_name
else
model_name
.
split
(
"=="
)[
0
]
self
.
args
=
self
.
parser
.
parse_args
(
argv
[
1
:])
self
.
args
=
self
.
parser
.
parse_args
(
argv
[
1
:])
if
not
self
.
args
.
output_path
:
self
.
args
.
type
=
self
.
check_type
(
self
.
args
.
type
)
self
.
args
.
output_path
=
"."
utils
.
check_path
(
self
.
args
.
output_path
)
search_result
=
default_hub_server
.
get_model_url
(
if
self
.
args
.
type
in
[
"Module"
,
"Model"
]:
model_name
,
version
=
model_version
)
search_result
=
default_hub_server
.
get_resource_url
(
mod_name
,
resource_type
=
self
.
args
.
type
,
version
=
mod_version
)
else
:
search_result
=
default_hub_server
.
get_resource_url
(
mod_name
,
resource_type
=
"Module"
,
version
=
mod_version
)
if
search_result
==
{}:
search_result
=
default_hub_server
.
get_resource_url
(
mod_name
,
resource_type
=
"Model"
,
version
=
mod_version
)
url
=
search_result
.
get
(
'url'
,
None
)
url
=
search_result
.
get
(
'url'
,
None
)
except_md5_value
=
search_result
.
get
(
'md5'
,
None
)
except_md5_value
=
search_result
.
get
(
'md5'
,
None
)
if
not
url
:
if
not
url
:
tips
=
"Can't found model
%s"
%
model
_name
tips
=
"Can't found model
/module %s"
%
mod
_name
if
model_version
:
if
model_version
:
tips
+=
" with version %s"
%
mod
el
_version
tips
+=
" with version %s"
%
mod_version
print
(
tips
)
print
(
tips
)
return
True
return
True
...
@@ -93,10 +97,20 @@ class DownloadCommand(BaseCommand):
...
@@ -93,10 +97,20 @@ class DownloadCommand(BaseCommand):
result
,
tips
,
file
=
default_downloader
.
uncompress
(
result
,
tips
,
file
=
default_downloader
.
uncompress
(
file
=
file
,
file
=
file
,
dirname
=
self
.
args
.
output_path
,
dirname
=
self
.
args
.
output_path
,
delete_file
=
Tru
e
,
delete_file
=
Fals
e
,
print_progress
=
True
)
print_progress
=
True
)
print
(
tips
)
print
(
tips
)
return
True
return
True
def
check_type
(
self
,
mod_type
):
mod_type
=
mod_type
.
lower
()
if
mod_type
==
"module"
:
mod_type
=
"Module"
elif
mod_type
==
"model"
:
mod_type
=
"Model"
else
:
mod_type
=
"All"
return
mod_type
command
=
DownloadCommand
.
instance
()
command
=
DownloadCommand
.
instance
()
paddlehub/commands/run.py
浏览文件 @
5ff5415f
...
@@ -18,6 +18,7 @@ from __future__ import print_function
...
@@ -18,6 +18,7 @@ from __future__ import print_function
import
argparse
import
argparse
import
os
import
os
import
sys
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.commands.base_command
import
BaseCommand
,
ENTRY
from
paddlehub.io.parser
import
yaml_parser
,
txt_parser
from
paddlehub.io.parser
import
yaml_parser
,
txt_parser
...
@@ -93,7 +94,14 @@ class RunCommand(BaseCommand):
...
@@ -93,7 +94,14 @@ class RunCommand(BaseCommand):
if
not
result
:
if
not
result
:
return
False
return
False
module
=
hub
.
Module
(
module_dir
=
module_dir
)
try
:
module
=
hub
.
Module
(
module_dir
=
module_dir
)
except
:
print
(
"ERROR! %s is a model. The command is only for the module type but not the model type."
%
module_name
)
sys
.
exit
(
0
)
self
.
parse_args_with_module
(
module
,
argv
[
1
:])
self
.
parse_args_with_module
(
module
,
argv
[
1
:])
if
not
module
.
default_signature
:
if
not
module
.
default_signature
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录