Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
be093813
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看板
提交
be093813
编写于
9月 16, 2020
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add paddlex utils
上级
66081648
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
90 addition
and
8 deletion
+90
-8
paddlehub/__init__.py
paddlehub/__init__.py
+2
-0
paddlehub/server/server_source.py
paddlehub/server/server_source.py
+24
-8
paddlehub/utils/paddlex.py
paddlehub/utils/paddlex.py
+64
-0
未找到文件。
paddlehub/__init__.py
浏览文件 @
be093813
...
...
@@ -20,6 +20,8 @@ from easydict import EasyDict
__version__
=
'2.0.0a0'
from
paddlehub.utils
import
log
,
parser
,
utils
from
paddlehub.utils.paddlex
import
download
,
ResourceNotFoundError
from
paddlehub.server.server_source
import
ServerConnectionError
from
paddlehub.module
import
Module
# In order to maintain the compatibility of the old version, we put the relevant
...
...
paddlehub/server/server_source.py
浏览文件 @
be093813
...
...
@@ -22,6 +22,15 @@ import paddlehub
from
paddlehub.utils
import
utils
class
ServerConnectionError
(
Exception
):
def
__init__
(
self
,
url
:
str
):
self
.
url
=
url
def
__str__
(
self
):
tips
=
'Can
\'
t connect to Hub Server: {}'
.
format
(
self
.
url
)
return
tips
class
ServerSource
(
object
):
'''
PaddleHub server source
...
...
@@ -30,6 +39,7 @@ class ServerSource(object):
url(str) : Url of the server
timeout(int) : Request timeout
'''
def
__init__
(
self
,
url
:
str
,
timeout
:
int
=
10
):
self
.
_url
=
url
self
.
_timeout
=
timeout
...
...
@@ -71,14 +81,20 @@ class ServerSource(object):
payload
[
'environments'
][
'platform_type'
]
=
platform
.
platform
()
api
=
'{}/search'
.
format
(
self
.
_url
)
result
=
requests
.
get
(
api
,
payload
,
timeout
=
self
.
_timeout
)
result
=
result
.
json
()
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
None
try
:
result
=
requests
.
get
(
api
,
payload
,
timeout
=
self
.
_timeout
)
result
=
result
.
json
()
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
else
:
print
(
result
)
return
None
except
requests
.
exceptions
.
ConnectionError
as
e
:
raise
ServerConnectionError
(
self
.
_url
)
@
classmethod
def
check
(
cls
,
url
:
str
)
->
bool
:
...
...
paddlehub/utils/paddlex.py
0 → 100644
浏览文件 @
be093813
# 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
os
import
shutil
from
paddlehub.server.server
import
module_server
from
paddlehub.utils
import
log
,
utils
,
xarfile
class
ResourceNotFoundError
(
Exception
):
def
__init__
(
self
,
name
:
str
,
version
:
str
=
None
):
self
.
name
=
name
self
.
version
=
version
def
__str__
(
self
):
if
not
self
.
version
:
tips
=
'No resource named {} was found'
.
format
(
self
.
name
)
else
:
tips
=
'No resource named {}-{} was found'
.
format
(
self
.
name
,
self
.
version
)
return
tips
def
download
(
name
:
str
,
save_path
:
str
,
version
:
str
=
None
):
'''
'''
file
=
os
.
path
.
join
(
save_path
,
name
)
file
=
os
.
path
.
realpath
(
file
)
if
os
.
path
.
exists
(
file
):
return
resource
=
module_server
.
search_resouce
(
name
=
name
,
version
=
version
,
type
=
'Model'
)
if
not
resource
:
raise
ResourceNotFoundError
(
name
,
version
)
url
=
resource
[
'url'
]
with
utils
.
generate_tempdir
()
as
_dir
:
if
not
os
.
path
.
exists
(
save_path
):
os
.
makedirs
(
save_path
)
with
log
.
ProgressBar
(
'Download {}'
.
format
(
url
))
as
_bar
:
for
savefile
,
dsize
,
tsize
in
utils
.
download_with_progress
(
url
,
_dir
):
_bar
.
update
(
float
(
dsize
/
tsize
))
if
xarfile
.
is_xarfile
(
savefile
):
with
log
.
ProgressBar
(
'Decompress {}'
.
format
(
savefile
))
as
_bar
:
for
savefile
,
usize
,
tsize
in
xarfile
.
unarchive_with_progress
(
savefile
,
_dir
):
_bar
.
update
(
float
(
usize
/
tsize
))
savefile
=
os
.
path
.
join
(
_dir
,
savefile
.
split
(
os
.
sep
)[
0
])
shutil
.
move
(
savefile
,
file
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录