Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
c3d0e3fb
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看板
未验证
提交
c3d0e3fb
编写于
11月 09, 2020
作者:
K
Kaipeng Deng
提交者:
GitHub
11月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check md5 before load weights. (#1663)
* check md5 before load weights.
上级
6f15306d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
18 deletion
+33
-18
ppdet/utils/download.py
ppdet/utils/download.py
+33
-18
未找到文件。
ppdet/utils/download.py
浏览文件 @
c3d0e3fb
...
...
@@ -124,8 +124,8 @@ def get_dataset_path(path, annotation, image_dir):
"Please apply and download the dataset from "
"https://www.objects365.org/download.html"
.
format
(
name
))
data_dir
=
osp
.
join
(
DATASET_HOME
,
name
)
# For
voc, only check dir VOCdevkit/VOC2012, VOCdevkit/VOC2007
if
name
==
'voc'
or
name
==
'fruit'
or
name
==
'roadsign_voc'
:
# For
VOC-style datasets, only check subdirs
if
name
in
[
'voc'
,
'fruit'
,
'roadsign_voc'
]
:
exists
=
True
for
sub_dir
in
dataset
[
1
]:
check_dir
=
osp
.
join
(
data_dir
,
sub_dir
)
...
...
@@ -203,20 +203,26 @@ 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
:
exist_flag
=
False
fullname
=
_download
(
url
,
root_dir
,
md5sum
)
# If fullpath is a directory, it has been decompressed
# checking MD5 is impossible, so we skip checking when
# fullpath is a directory here
if
osp
.
isdir
(
fullpath
)
or
\
_md5check_from_req
(
fullpath
,
requests
.
get
(
url
,
stream
=
True
)):
logger
.
debug
(
"Found {}"
.
format
(
fullpath
))
return
fullpath
,
True
else
:
shutil
.
rmtree
(
fullpath
)
# new weights format which postfix is 'pdparams' not
# need to decompress
if
osp
.
splitext
(
fullname
)[
-
1
]
!=
'.pdparams'
:
_decompress
(
fullname
)
fullname
=
_download
(
url
,
root_dir
,
md5sum
)
return
fullpath
,
exist_flag
# new weights format whose postfix is 'pdparams',
# which is not need to decompress
if
osp
.
splitext
(
fullname
)[
-
1
]
!=
'.pdparams'
:
_decompress
(
fullname
)
return
fullpath
,
False
def
download_dataset
(
path
,
dataset
=
None
):
...
...
@@ -308,11 +314,7 @@ def _download(url, path, md5sum=None):
f
.
write
(
chunk
)
# check md5 after download in Content-MD5 in req.headers
content_md5
=
req
.
headers
.
get
(
'content-md5'
)
if
not
content_md5
or
_md5check
(
tmp_fullname
,
binascii
.
hexlify
(
base64
.
b64decode
(
content_md5
.
strip
(
'"'
))).
decode
()):
if
_md5check_from_req
(
tmp_fullname
,
req
):
shutil
.
move
(
tmp_fullname
,
fullname
)
return
fullname
else
:
...
...
@@ -322,6 +324,19 @@ def _download(url, path, md5sum=None):
continue
def
_md5check_from_req
(
weights_path
,
req
):
# For weights in bcebos URLs, MD5 value is contained
# in request header as 'content_md5'
content_md5
=
req
.
headers
.
get
(
'content-md5'
)
if
not
content_md5
or
_md5check
(
weights_path
,
binascii
.
hexlify
(
base64
.
b64decode
(
content_md5
.
strip
(
'"'
))).
decode
(
)):
return
True
else
:
return
False
def
_md5check
(
fullname
,
md5sum
=
None
):
if
md5sum
is
None
:
return
True
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录