Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PALM
提交
4d23b9da
P
PALM
项目概览
PaddlePaddle
/
PALM
通知
5
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看板
提交
4d23b9da
编写于
11月 28, 2019
作者:
W
wangxiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update downloader.py
上级
19370b22
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
7 deletion
+49
-7
paddlepalm/downloader.py
paddlepalm/downloader.py
+49
-7
未找到文件。
paddlepalm/downloader.py
浏览文件 @
4d23b9da
...
...
@@ -15,6 +15,8 @@
from
__future__
import
print_function
import
os
import
tarfile
import
shutil
try
:
from
urllib.request
import
urlopen
# Python 3
except
ImportError
:
...
...
@@ -40,16 +42,19 @@ def _download(item, scope, path, silent=False):
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
]
data_name
=
data_url
.
split
(
'/'
)[
-
1
]
filename
=
data_dir
+
'/'
+
data_name
def
chunk_report
(
bytes_so_far
,
total_size
):
# print process
def
_chunk_report
(
bytes_so_far
,
total_size
):
percent
=
float
(
bytes_so_far
)
/
float
(
total_size
)
if
percent
>
1
:
percent
=
1
if
not
silent
:
print
(
'
\r
>> Downloading... {:.1%}'
.
format
(
percent
),
end
=
""
)
def
chunk_read
(
response
,
url
,
chunk_size
=
16
*
1024
,
report_hook
=
None
):
# copy to local
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
...
...
@@ -66,14 +71,51 @@ def _download(item, scope, path, silent=False):
return
bytes_so_far
response
=
urlopen
(
data_url
)
chunk_read
(
response
,
data_url
,
report_hook
=
chunk_report
)
_chunk_read
(
response
,
data_url
,
report_hook
=
_
chunk_report
)
if
not
silent
:
print
(
' done!'
)
if
item
==
'pretrain'
:
if
not
silent
:
print
(
'Extracting {}...'
.
format
(
data_name
),
end
=
" "
)
if
os
.
path
.
exists
(
filename
):
tar
=
tarfile
.
open
(
filename
,
'r'
)
tar
.
extractall
(
path
=
data_dir
)
tar
.
close
()
os
.
remove
(
filename
)
if
not
silent
:
print
(
'done!'
)
if
not
silent
:
print
(
'Converting params...'
,
end
=
" "
)
_convert
(
data_dir
+
'/'
+
data_name
.
split
(
'.'
)[
0
],
silent
)
if
not
silent
:
print
(
'done!'
)
def
_convert
():
raise
NotImplementedError
()
def
_convert
(
path
,
silent
=
False
):
if
os
.
path
.
isfile
(
path
+
'/params/__palminfo__'
):
if
not
silent
:
print
(
'already converted.'
)
else
:
if
os
.
path
.
exists
(
path
+
'/params/'
):
os
.
rename
(
path
+
'/params/'
,
path
+
'/params1/'
)
os
.
mkdir
(
path
+
'/params/'
)
tar_model
=
tarfile
.
open
(
path
+
'/params/'
+
'__palmmodel__'
,
'w:gz'
)
tar_info
=
open
(
path
+
'/params/'
+
'__palminfo__'
,
'w'
)
for
root
,
dirs
,
files
in
os
.
walk
(
path
+
'/params1/'
):
for
file
in
files
:
src_file
=
os
.
path
.
join
(
root
,
file
)
newname
=
path
+
'/params1/'
+
'__paddlepalm_'
+
file
os
.
rename
(
src_file
,
newname
)
tar_model
.
add
(
newname
)
tar_info
.
write
(
newname
)
os
.
remove
(
newname
)
tar_model
.
close
()
tar_info
.
close
()
os
.
removedirs
(
path
+
'/params1/'
)
# raise NotImplementedError()
def
download
(
item
,
scope
=
'all'
,
path
=
'.'
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录