Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PALM
提交
d2bbdfd0
P
PALM
项目概览
PaddlePaddle
/
PALM
通知
7
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PALM
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d2bbdfd0
编写于
11月 28, 2019
作者:
W
wangxiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update downloader.py
上级
a7f7dc4c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
70 addition
and
20 deletion
+70
-20
paddlepalm/downloader.py
paddlepalm/downloader.py
+70
-20
未找到文件。
paddlepalm/downloader.py
浏览文件 @
d2bbdfd0
# -*- 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.
from
__future__
import
print_function
import
os
try
:
from
urllib.request
import
urlopen
# Python 3
except
ImportError
:
from
urllib2
import
urlopen
# Python 2
# for https
import
ssl
ssl
.
_create_default_https_context
=
ssl
.
_create_unverified_context
_items
=
{
'pretrain'
:
{
'ernie-en-uncased-large'
:
'http://xxxxx'
,
'xxx'
:
'xxx'
,
'utils'
:
None
}
'reader'
:
{
'cls'
:
'xxx'
,
'xxx'
:
'xxx'
,
'utils'
:
'xxx'
}
'backbone'
:
{
xxx
}
'tasktype'
:
{
xxx
}
'pretrain'
:
{
'ernie-en-uncased-large'
:
'https://ernie.bj.bcebos.com/ERNIE_Large_en_stable-2.0.0.tar.gz'
,
'bert-en-uncased-large'
:
'https://bert-models.bj.bcebos.com/uncased_L-24_H-1024_A-16.tar.gz'
,
'utils'
:
None
},
'reader'
:
{
'utils'
:
None
},
'backbone'
:
{
'utils'
:
None
},
'tasktype'
:
{
'utils'
:
None
},
}
def
demo
():
raise
NotImplementedError
()
def
_convert
():
raise
NotImplementedError
()
def
download
(
item
,
scope
=
'all'
,
path
=
'.'
):
item
=
item
.
lower
()
scope
=
scope
.
lower
()
assert
item
in
items
,
'{} is not found. Support list: {}'
.
format
(
item
,
list
(
items
.
keys
()))
assert
item
in
_items
,
'{} is not found. Support list: {}'
.
format
(
item
,
list
(
_items
.
keys
()))
# if not os.path.exists(path + '/' + item):
# os.makedirs(os.path.join(path + '/' + item))
if
not
os
.
path
.
exists
(
path
,
item
):
os
.
makedirs
(
os
.
path
.
join
(
path
,
item
))
def
_download
(
item
,
scope
,
silent
=
False
):
if
not
silent
:
print
(
'downloading {}: {} from {}...'
.
format
(
item
,
scope
,
items
[
item
][
scope
]),
end
=
''
)
urllib
.
downloadxxx
(
items
[
item
][
scope
],
path
)
print
(
'Downloading {}: {} from {}...'
.
format
(
item
,
scope
,
_items
[
item
][
scope
]))
data_url
=
_items
[
item
][
scope
]
data_dir
=
path
+
'/'
+
item
+
'/'
+
scope
if
not
os
.
path
.
exists
(
data_dir
):
os
.
makedirs
(
os
.
path
.
join
(
data_dir
))
filename
=
data_dir
+
'/'
+
data_url
.
split
(
'/'
)[
-
1
]
def
chunk_report
(
bytes_so_far
,
total_size
):
percent
=
float
(
bytes_so_far
)
/
float
(
total_size
)
*
100.0
if
percent
>
100
:
percent
=
100
if
not
silent
:
print
(
'
\r
>> Downloading... %.1f%%'
%
percent
,
end
=
"
\r
"
)
def
chunk_read
(
response
,
url
,
chunk_size
=
16
*
1024
,
report_hook
=
None
):
total_size
=
response
.
info
().
getheader
(
'Content-Length'
).
strip
()
total_size
=
int
(
total_size
)
bytes_so_far
=
0
with
open
(
"%s"
%
filename
,
"wb"
)
as
f
:
while
1
:
chunk
=
response
.
read
(
chunk_size
)
f
.
write
(
chunk
)
f
.
flush
()
bytes_so_far
+=
len
(
chunk
)
if
not
chunk
:
break
if
report_hook
:
report_hook
(
bytes_so_far
,
total_size
)
return
bytes_so_far
response
=
urlopen
(
data_url
)
chunk_read
(
response
,
data_url
,
report_hook
=
chunk_report
)
if
not
silent
:
print
(
'done!'
)
if
items
[
'utils'
]
is
not
None
:
if
_items
[
item
]
[
'utils'
]
is
not
None
:
_download
(
item
,
'utils'
,
silent
=
True
)
if
scope
!=
'all'
:
assert
scope
in
items
[
item
],
'{} is not found. Support scopes: {}'
.
format
(
item
,
list
(
items
[
item
].
keys
()))
assert
scope
in
_items
[
item
],
'{} is not found. Support scopes: {}'
.
format
(
item
,
list
(
_
items
[
item
].
keys
()))
_download
(
item
,
scope
)
else
:
for
s
in
items
[
item
].
keys
():
for
s
in
_
items
[
item
].
keys
():
_download
(
item
,
s
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录