Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
10e43271
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看板
未验证
提交
10e43271
编写于
6月 17, 2020
作者:
走神的阿圆
提交者:
GitHub
6月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add stat for paddlex (#698)
* Change path of CacheUpdater.
上级
90ef69ac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
58 deletion
+76
-58
paddlehub/__init__.py
paddlehub/__init__.py
+1
-1
paddlehub/common/downloader.py
paddlehub/common/downloader.py
+0
-57
paddlehub/common/paddlex_utils.py
paddlehub/common/paddlex_utils.py
+75
-0
未找到文件。
paddlehub/__init__.py
浏览文件 @
10e43271
...
@@ -41,7 +41,7 @@ from .common.logger import logger
...
@@ -41,7 +41,7 @@ from .common.logger import logger
from
.common.paddle_helper
import
connect_program
from
.common.paddle_helper
import
connect_program
from
.common.hub_server
import
HubServer
from
.common.hub_server
import
HubServer
from
.common.hub_server
import
server_check
from
.common.hub_server
import
server_check
from
.common.
downloader
import
download
,
ResourceNotFoundError
,
ServerConnectionError
from
.common.
paddlex_utils
import
download
,
ResourceNotFoundError
,
ServerConnectionError
from
.module.module
import
Module
from
.module.module
import
Module
from
.module.base_processor
import
BaseProcessor
from
.module.base_processor
import
BaseProcessor
...
...
paddlehub/common/downloader.py
浏览文件 @
10e43271
...
@@ -27,9 +27,6 @@ import requests
...
@@ -27,9 +27,6 @@ import requests
import
tarfile
import
tarfile
from
paddlehub.common
import
utils
from
paddlehub.common
import
utils
from
paddlehub.common.logger
import
logger
from
paddlehub.common
import
tmp_dir
from
paddlehub.common.hub_server
import
CacheUpdater
import
paddlehub
as
hub
import
paddlehub
as
hub
__all__
=
[
'Downloader'
,
'progress'
]
__all__
=
[
'Downloader'
,
'progress'
]
...
@@ -156,57 +153,3 @@ class Downloader(object):
...
@@ -156,57 +153,3 @@ class Downloader(object):
default_downloader
=
Downloader
()
default_downloader
=
Downloader
()
class
ResourceNotFoundError
(
Exception
):
def
__init__
(
self
,
name
,
version
=
None
):
self
.
name
=
name
self
.
version
=
version
def
__str__
(
self
):
if
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
class
ServerConnectionError
(
Exception
):
def
__str__
(
self
):
tips
=
'Can
\'
t connect to Hub Server:{}'
.
format
(
hub
.
HubServer
().
server_url
[
0
])
return
tips
def
download
(
name
,
save_path
,
version
=
None
,
decompress
=
True
,
resource_type
=
'Model'
,
extra
=
None
):
file
=
os
.
path
.
join
(
save_path
,
name
)
file
=
os
.
path
.
realpath
(
file
)
if
os
.
path
.
exists
(
file
):
return
if
not
hub
.
HubServer
().
_server_check
():
raise
ServerConnectionError
search_result
=
hub
.
HubServer
().
get_resource_url
(
name
,
resource_type
=
resource_type
,
version
=
version
,
extra
=
extra
)
if
not
search_result
:
raise
ResourceNotFoundError
(
name
,
version
)
CacheUpdater
(
"hub_download"
,
name
,
version
).
start
()
url
=
search_result
[
'url'
]
with
tmp_dir
()
as
_dir
:
if
not
os
.
path
.
exists
(
save_path
):
os
.
makedirs
(
save_path
)
_
,
_
,
savefile
=
default_downloader
.
download_file
(
url
=
url
,
save_path
=
_dir
,
print_progress
=
True
)
if
tarfile
.
is_tarfile
(
savefile
)
and
decompress
:
_
,
_
,
savefile
=
default_downloader
.
uncompress
(
file
=
savefile
,
print_progress
=
True
)
shutil
.
move
(
savefile
,
file
)
paddlehub/common/paddlex_utils.py
0 → 100644
浏览文件 @
10e43271
#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
tarfile
import
shutil
from
paddlehub.common
import
tmp_dir
from
paddlehub.common.hub_server
import
CacheUpdater
from
paddlehub.common.downloader
import
default_downloader
import
paddlehub
as
hub
class
ResourceNotFoundError
(
Exception
):
def
__init__
(
self
,
name
,
version
=
None
):
self
.
name
=
name
self
.
version
=
version
def
__str__
(
self
):
if
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
class
ServerConnectionError
(
Exception
):
def
__str__
(
self
):
tips
=
'Can
\'
t connect to Hub Server:{}'
.
format
(
hub
.
HubServer
().
server_url
[
0
])
return
tips
def
download
(
name
,
save_path
,
version
=
None
,
decompress
=
True
,
resource_type
=
'Model'
,
extra
=
None
):
file
=
os
.
path
.
join
(
save_path
,
name
)
file
=
os
.
path
.
realpath
(
file
)
if
os
.
path
.
exists
(
file
):
return
if
not
hub
.
HubServer
().
_server_check
():
raise
ServerConnectionError
search_result
=
hub
.
HubServer
().
get_resource_url
(
name
,
resource_type
=
resource_type
,
version
=
version
,
extra
=
extra
)
if
not
search_result
:
raise
ResourceNotFoundError
(
name
,
version
)
CacheUpdater
(
"hub_download"
,
name
,
version
).
start
()
url
=
search_result
[
'url'
]
with
tmp_dir
()
as
_dir
:
if
not
os
.
path
.
exists
(
save_path
):
os
.
makedirs
(
save_path
)
_
,
_
,
savefile
=
default_downloader
.
download_file
(
url
=
url
,
save_path
=
_dir
,
print_progress
=
True
)
if
tarfile
.
is_tarfile
(
savefile
)
and
decompress
:
_
,
_
,
savefile
=
default_downloader
.
uncompress
(
file
=
savefile
,
print_progress
=
True
)
shutil
.
move
(
savefile
,
file
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录