Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
f24c1b05
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f24c1b05
编写于
4月 14, 2021
作者:
K
Kaipeng Deng
提交者:
GitHub
4月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix re-download not trigger when weights update (#2617)
上级
f161d2a1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
14 deletion
+40
-14
ppdet/utils/download.py
ppdet/utils/download.py
+40
-14
未找到文件。
ppdet/utils/download.py
浏览文件 @
f24c1b05
...
...
@@ -23,6 +23,8 @@ import shutil
import
requests
import
tqdm
import
hashlib
import
base64
import
binascii
import
tarfile
import
zipfile
...
...
@@ -257,20 +259,21 @@ def get_path(url, root_dir, md5sum=None, check_exist=True):
if
fullpath
.
find
(
k
)
>=
0
:
fullpath
=
osp
.
join
(
osp
.
split
(
fullpath
)[
0
],
v
)
exist_flag
=
False
if
osp
.
exists
(
fullpath
)
and
check_exist
:
exist_flag
=
True
logger
.
debug
(
"Found {}"
.
format
(
fullpath
))
else
:
e
xist_flag
=
False
fullname
=
_download
(
url
,
root_dir
,
md5sum
)
if
_check_exist_file_md5
(
fullpath
,
md5sum
,
url
):
logger
.
debug
(
"Found {}"
.
format
(
fullpath
))
return
fullpath
,
True
e
lse
:
os
.
remove
(
fullpath
)
# new weights format which postfix is 'pdparams' not
# need to decompress
if
osp
.
splitext
(
fullname
)[
-
1
]
not
in
[
'.pdparams'
,
'.yml'
]:
_decompress
(
fullname
)
fullname
=
_download
(
url
,
root_dir
,
md5sum
)
return
fullpath
,
exist_flag
# new weights format which postfix is 'pdparams' not
# need to decompress
if
osp
.
splitext
(
fullname
)[
-
1
]
not
in
[
'.pdparams'
,
'.yml'
]:
_decompress
(
fullname
)
return
fullpath
,
False
def
download_dataset
(
path
,
dataset
=
None
):
...
...
@@ -324,7 +327,8 @@ def _download(url, path, md5sum=None):
fullname
=
osp
.
join
(
path
,
fname
)
retry_cnt
=
0
while
not
(
osp
.
exists
(
fullname
)
and
_md5check
(
fullname
,
md5sum
)):
while
not
(
osp
.
exists
(
fullname
)
and
_check_exist_file_md5
(
fullname
,
md5sum
,
url
)):
if
retry_cnt
<
DOWNLOAD_RETRY_LIMIT
:
retry_cnt
+=
1
else
:
...
...
@@ -355,8 +359,30 @@ def _download(url, path, md5sum=None):
if
chunk
:
f
.
write
(
chunk
)
shutil
.
move
(
tmp_fullname
,
fullname
)
return
fullname
return
fullname
def
_check_exist_file_md5
(
filename
,
md5sum
,
url
):
# if md5sum is None, and file to check is weights file,
# read md5um from url and check, else check md5sum directly
return
_md5check_from_url
(
filename
,
url
)
if
md5sum
is
None
\
and
filename
.
endswith
(
'pdparams'
)
\
else
_md5check
(
filename
,
md5sum
)
def
_md5check_from_url
(
filename
,
url
):
# For weights in bcebos URLs, MD5 value is contained
# in request header as 'content_md5'
req
=
requests
.
get
(
url
,
stream
=
True
)
content_md5
=
req
.
headers
.
get
(
'content-md5'
)
req
.
close
()
if
not
content_md5
or
_md5check
(
filename
,
binascii
.
hexlify
(
base64
.
b64decode
(
content_md5
.
strip
(
'"'
))).
decode
(
)):
return
True
else
:
return
False
def
_md5check
(
fullname
,
md5sum
=
None
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录