Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
8917fb23
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看板
提交
8917fb23
编写于
9月 24, 2020
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add search command
上级
80476dde
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
84 addition
and
37 deletion
+84
-37
paddlehub/commands/search.py
paddlehub/commands/search.py
+40
-0
paddlehub/module/manager.py
paddlehub/module/manager.py
+23
-22
paddlehub/server/git_source.py
paddlehub/server/git_source.py
+5
-4
paddlehub/server/server.py
paddlehub/server/server.py
+4
-3
paddlehub/server/server_source.py
paddlehub/server/server_source.py
+3
-5
paddlehub/utils/paddlex.py
paddlehub/utils/paddlex.py
+9
-3
未找到文件。
paddlehub/commands/search.py
浏览文件 @
8917fb23
#coding:utf-8
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
argparse
import
os
from
typing
import
List
from
paddlehub.commands
import
register
from
paddlehub.module.manager
import
LocalModuleManager
from
paddlehub.server.server
import
module_server
from
paddlehub.utils
import
log
,
platform
@
register
(
name
=
'hub.search'
,
description
=
'Search PaddleHub pretrained model through model keywords.'
)
class
SearchCommand
:
def
execute
(
self
,
argv
:
List
)
->
bool
:
argv
=
'.*'
if
not
argv
else
argv
[
0
]
widths
=
[
20
,
8
,
30
]
if
platform
.
is_windows
()
else
[
30
,
8
,
40
]
table
=
log
.
Table
(
widths
=
widths
)
table
.
append
(
*
[
'ModuleName'
,
'Version'
,
'Summary'
],
aligns
=
[
'^'
,
'^'
,
'^'
],
colors
=
[
"blue"
,
"blue"
,
"blue"
])
results
=
module_server
.
search_module
(
name
=
argv
)
for
result
in
results
:
table
.
append
(
result
[
'name'
],
result
[
'version'
],
result
[
'summary'
])
print
(
table
)
return
True
paddlehub/module/manager.py
浏览文件 @
8917fb23
...
...
@@ -238,7 +238,12 @@ class LocalModuleManager(object):
return
self
.
_local_modules
[
name
]
result
=
module_server
.
search_module
(
name
=
name
,
version
=
version
,
source
=
source
)
if
not
result
:
for
item
in
result
:
if
name
.
lower
()
==
item
[
'name'
].
lower
()
and
utils
.
Version
(
item
[
'version'
]).
match
(
version
):
if
source
or
'source'
in
item
:
return
self
.
_install_from_source
(
result
)
return
self
.
_install_from_url
(
item
[
'url'
])
module_infos
=
module_server
.
get_module_info
(
name
=
name
,
source
=
source
)
# The HubModule with the specified name cannot be found
if
not
module_infos
:
...
...
@@ -257,10 +262,6 @@ class LocalModuleManager(object):
raise
EnvironmentMismatchError
(
name
=
name
,
info
=
valid_infos
,
version
=
version
)
raise
HubModuleNotFoundError
(
name
=
name
,
info
=
module_infos
,
version
=
version
,
source
=
source
)
if
source
or
'source'
in
result
:
return
self
.
_install_from_source
(
result
)
return
self
.
_install_from_url
(
result
[
'url'
])
def
_install_from_source
(
self
,
source
:
str
)
->
HubModule
:
'''Install a HubModule from Git Repo'''
name
=
source
[
'name'
]
...
...
paddlehub/server/git_source.py
浏览文件 @
8917fb23
...
...
@@ -18,6 +18,7 @@ import importlib
import
os
import
sys
from
collections
import
OrderedDict
from
typing
import
List
from
urllib.parse
import
urlparse
import
git
...
...
@@ -74,7 +75,7 @@ class GitSource(object):
log
.
logger
.
warning
(
'An error occurred while loading {}'
.
format
(
self
.
path
))
sys
.
path
.
remove
(
self
.
path
)
def
search_module
(
self
,
name
:
str
,
version
:
str
=
None
)
->
dict
:
def
search_module
(
self
,
name
:
str
,
version
:
str
=
None
)
->
List
[
dict
]
:
'''
Search PaddleHub module
...
...
@@ -84,7 +85,7 @@ class GitSource(object):
'''
return
self
.
search_resource
(
type
=
'module'
,
name
=
name
,
version
=
version
)
def
search_resource
(
self
,
type
:
str
,
name
:
str
,
version
:
str
=
None
)
->
dict
:
def
search_resource
(
self
,
type
:
str
,
name
:
str
,
version
:
str
=
None
)
->
List
[
dict
]
:
'''
Search PaddleHub Resource
...
...
@@ -95,13 +96,13 @@ class GitSource(object):
'''
module
=
self
.
hub_modules
.
get
(
name
,
None
)
if
module
and
module
.
version
.
match
(
version
):
return
{
return
[
{
'version'
:
module
.
version
,
'name'
:
module
.
name
,
'path'
:
self
.
path
,
'class'
:
module
.
__name__
,
'source'
:
self
.
url
}
}
]
return
None
@
classmethod
...
...
paddlehub/server/server.py
浏览文件 @
8917fb23
...
...
@@ -14,6 +14,7 @@
# limitations under the License.
from
collections
import
OrderedDict
from
typing
import
List
from
paddlehub.server
import
ServerSource
,
GitSource
...
...
@@ -44,7 +45,7 @@ class HubServer(object):
'''Remove a module source'''
self
.
sources
.
pop
(
key
)
def
search_module
(
self
,
name
:
str
,
version
:
str
=
None
,
source
:
str
=
None
)
->
dict
:
def
search_module
(
self
,
name
:
str
,
version
:
str
=
None
,
source
:
str
=
None
)
->
List
[
dict
]
:
'''
Search PaddleHub module
...
...
@@ -54,7 +55,7 @@ class HubServer(object):
'''
return
self
.
search_resource
(
type
=
'module'
,
name
=
name
,
version
=
version
,
source
=
source
)
def
search_resource
(
self
,
type
:
str
,
name
:
str
,
version
:
str
=
None
,
source
:
str
=
None
)
->
dict
:
def
search_resource
(
self
,
type
:
str
,
name
:
str
,
version
:
str
=
None
,
source
:
str
=
None
)
->
List
[
dict
]
:
'''
Search PaddleHub Resource
...
...
@@ -68,7 +69,7 @@ class HubServer(object):
result
=
source
.
search_resource
(
name
=
name
,
type
=
type
,
version
=
version
)
if
result
:
return
result
return
{}
return
[]
def
get_module_info
(
self
,
name
:
str
,
source
:
str
=
None
)
->
dict
:
'''
...
...
paddlehub/server/server_source.py
浏览文件 @
8917fb23
...
...
@@ -43,7 +43,7 @@ class ServerSource(object):
self
.
_url
=
url
self
.
_timeout
=
timeout
def
search_module
(
self
,
name
:
str
,
version
:
str
=
None
)
->
dict
:
def
search_module
(
self
,
name
:
str
,
version
:
str
=
None
)
->
List
[
dict
]
:
'''
Search PaddleHub module
...
...
@@ -53,7 +53,7 @@ class ServerSource(object):
'''
return
self
.
search_resource
(
type
=
'module'
,
name
=
name
,
version
=
version
)
def
search_resource
(
self
,
type
:
str
,
name
:
str
,
version
:
str
=
None
)
->
dict
:
def
search_resource
(
self
,
type
:
str
,
name
:
str
,
version
:
str
=
None
)
->
List
[
dict
]
:
'''
Search PaddleHub Resource
...
...
@@ -76,9 +76,7 @@ class ServerSource(object):
result
=
self
.
request
(
path
=
'search'
,
params
=
params
)
if
result
[
'status'
]
==
0
and
len
(
result
[
'data'
])
>
0
:
for
item
in
result
[
'data'
]:
if
name
.
lower
()
==
item
[
'name'
].
lower
()
and
utils
.
Version
(
item
[
'version'
]).
match
(
version
):
return
item
return
result
[
'data'
]
return
None
def
get_module_info
(
self
,
name
:
str
)
->
dict
:
...
...
paddlehub/utils/paddlex.py
浏览文件 @
8917fb23
...
...
@@ -41,11 +41,17 @@ def download(name: str, save_path: str, version: str = None):
if
os
.
path
.
exists
(
file
):
return
resource
=
module_server
.
search_resouce
(
name
=
name
,
version
=
version
,
type
=
'Model'
)
if
not
resource
:
resources
=
module_server
.
search_resouce
(
name
=
name
,
version
=
version
,
type
=
'Model'
)
if
not
resources
:
raise
ResourceNotFoundError
(
name
,
version
)
for
item
in
resources
:
if
item
[
'name'
]
==
name
and
utils
.
Version
(
item
[
'version'
]).
match
(
version
):
url
=
item
[
'url'
]
break
else
:
raise
ResourceNotFoundError
(
name
,
version
)
url
=
resource
[
'url'
]
with
utils
.
generate_tempdir
()
as
_dir
:
if
not
os
.
path
.
exists
(
save_path
):
os
.
makedirs
(
save_path
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录