Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
5f1000a4
Unverified
提交
5f1000a4
authored
8月 30, 2022
作者:
Yannick Merkli
提交者:
GitHub
8月 30, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove usage of `pathlib.Path.unlink(missing_ok=...)` (#9227)
remove usage of pathlib.Path.unlink(missing_ok=...) Co-authored-by:
Yannick Merkli
<
ymerkli@latticeflow.ai
>
上级
4a37381e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
7 行删除
+15
-7
dataloaders.py
utils/dataloaders.py
+3
-1
downloads.py
utils/downloads.py
+12
-6
没有找到文件。
utils/dataloaders.py
浏览文件 @
5f1000a4
...
@@ -917,7 +917,9 @@ def autosplit(path=DATASETS_DIR / 'coco128/images', weights=(0.9, 0.1, 0.0), ann
...
@@ -917,7 +917,9 @@ def autosplit(path=DATASETS_DIR / 'coco128/images', weights=(0.9, 0.1, 0.0), ann
indices
=
random
.
choices
([
0
,
1
,
2
],
weights
=
weights
,
k
=
n
)
# assign each image to a split
indices
=
random
.
choices
([
0
,
1
,
2
],
weights
=
weights
,
k
=
n
)
# assign each image to a split
txt
=
[
'autosplit_train.txt'
,
'autosplit_val.txt'
,
'autosplit_test.txt'
]
# 3 txt files
txt
=
[
'autosplit_train.txt'
,
'autosplit_val.txt'
,
'autosplit_test.txt'
]
# 3 txt files
[(
path
.
parent
/
x
)
.
unlink
(
missing_ok
=
True
)
for
x
in
txt
]
# remove existing
for
x
in
txt
:
if
(
path
.
parent
/
x
)
.
exists
():
(
path
.
parent
/
x
)
.
unlink
()
# remove existing
print
(
f
'Autosplitting images from {path}'
+
', using *.txt labeled images only'
*
annotated_only
)
print
(
f
'Autosplitting images from {path}'
+
', using *.txt labeled images only'
*
annotated_only
)
for
i
,
img
in
tqdm
(
zip
(
indices
,
files
),
total
=
n
):
for
i
,
img
in
tqdm
(
zip
(
indices
,
files
),
total
=
n
):
...
...
utils/downloads.py
浏览文件 @
5f1000a4
...
@@ -44,12 +44,14 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''):
...
@@ -44,12 +44,14 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''):
torch
.
hub
.
download_url_to_file
(
url
,
str
(
file
),
progress
=
LOGGER
.
level
<=
logging
.
INFO
)
torch
.
hub
.
download_url_to_file
(
url
,
str
(
file
),
progress
=
LOGGER
.
level
<=
logging
.
INFO
)
assert
file
.
exists
()
and
file
.
stat
()
.
st_size
>
min_bytes
,
assert_msg
# check
assert
file
.
exists
()
and
file
.
stat
()
.
st_size
>
min_bytes
,
assert_msg
# check
except
Exception
as
e
:
# url2
except
Exception
as
e
:
# url2
file
.
unlink
(
missing_ok
=
True
)
# remove partial downloads
if
file
.
exists
():
file
.
unlink
()
# remove partial downloads
LOGGER
.
info
(
f
'ERROR: {e}
\n
Re-attempting {url2 or url} to {file}...'
)
LOGGER
.
info
(
f
'ERROR: {e}
\n
Re-attempting {url2 or url} to {file}...'
)
os
.
system
(
f
"curl -# -L '{url2 or url}' -o '{file}' --retry 3 -C -"
)
# curl download, retry and resume on fail
os
.
system
(
f
"curl -# -L '{url2 or url}' -o '{file}' --retry 3 -C -"
)
# curl download, retry and resume on fail
finally
:
finally
:
if
not
file
.
exists
()
or
file
.
stat
()
.
st_size
<
min_bytes
:
# check
if
not
file
.
exists
()
or
file
.
stat
()
.
st_size
<
min_bytes
:
# check
file
.
unlink
(
missing_ok
=
True
)
# remove partial downloads
if
file
.
exists
():
file
.
unlink
()
# remove partial downloads
LOGGER
.
info
(
f
"ERROR: {assert_msg}
\n
{error_msg}"
)
LOGGER
.
info
(
f
"ERROR: {assert_msg}
\n
{error_msg}"
)
LOGGER
.
info
(
''
)
LOGGER
.
info
(
''
)
...
@@ -112,8 +114,10 @@ def gdrive_download(id='16TiPfZj7htmTyhntwcZyEEAejOUxuT6m', file='tmp.zip'):
...
@@ -112,8 +114,10 @@ def gdrive_download(id='16TiPfZj7htmTyhntwcZyEEAejOUxuT6m', file='tmp.zip'):
file
=
Path
(
file
)
file
=
Path
(
file
)
cookie
=
Path
(
'cookie'
)
# gdrive cookie
cookie
=
Path
(
'cookie'
)
# gdrive cookie
print
(
f
'Downloading https://drive.google.com/uc?export=download&id={id} as {file}... '
,
end
=
''
)
print
(
f
'Downloading https://drive.google.com/uc?export=download&id={id} as {file}... '
,
end
=
''
)
file
.
unlink
(
missing_ok
=
True
)
# remove existing file
if
file
.
exists
():
cookie
.
unlink
(
missing_ok
=
True
)
# remove existing cookie
file
.
unlink
()
# remove existing file
if
cookie
.
exists
():
cookie
.
unlink
()
# remove existing cookie
# Attempt file download
# Attempt file download
out
=
"NUL"
if
platform
.
system
()
==
"Windows"
else
"/dev/null"
out
=
"NUL"
if
platform
.
system
()
==
"Windows"
else
"/dev/null"
...
@@ -123,11 +127,13 @@ def gdrive_download(id='16TiPfZj7htmTyhntwcZyEEAejOUxuT6m', file='tmp.zip'):
...
@@ -123,11 +127,13 @@ def gdrive_download(id='16TiPfZj7htmTyhntwcZyEEAejOUxuT6m', file='tmp.zip'):
else
:
# small file
else
:
# small file
s
=
f
'curl -s -L -o {file} "drive.google.com/uc?export=download&id={id}"'
s
=
f
'curl -s -L -o {file} "drive.google.com/uc?export=download&id={id}"'
r
=
os
.
system
(
s
)
# execute, capture return
r
=
os
.
system
(
s
)
# execute, capture return
cookie
.
unlink
(
missing_ok
=
True
)
# remove existing cookie
if
cookie
.
exists
():
cookie
.
unlink
()
# remove existing cookie
# Error check
# Error check
if
r
!=
0
:
if
r
!=
0
:
file
.
unlink
(
missing_ok
=
True
)
# remove partial
if
file
.
exists
():
file
.
unlink
()
# remove partial
print
(
'Download error '
)
# raise Exception('Download error')
print
(
'Download error '
)
# raise Exception('Download error')
return
r
return
r
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论