Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
7820614c
Unverified
提交
7820614c
authored
7月 29, 2021
作者:
Glenn Jocher
提交者:
GitHub
7月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `@try_except` decorator (#4224)
上级
b60b62e8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
22 行删除
+31
-22
general.py
utils/general.py
+31
-22
没有找到文件。
utils/general.py
浏览文件 @
7820614c
...
...
@@ -56,6 +56,17 @@ class timeout(contextlib.ContextDecorator):
return
True
def
try_except
(
func
):
# try-except function. Usage: @try_except decorator
def
handler
(
*
args
,
**
kwargs
):
try
:
func
(
*
args
,
**
kwargs
)
except
Exception
as
e
:
print
(
e
)
return
handler
def
set_logging
(
rank
=-
1
,
verbose
=
True
):
logging
.
basicConfig
(
format
=
"
%(message)
s"
,
...
...
@@ -114,26 +125,25 @@ def check_online():
return
False
def
check_git_status
(
err_msg
=
', for updates see https://github.com/ultralytics/yolov5'
):
@try_except
def
check_git_status
():
# Recommend 'git pull' if code is out of date
msg
=
', for updates see https://github.com/ultralytics/yolov5'
print
(
colorstr
(
'github: '
),
end
=
''
)
try
:
assert
Path
(
'.git'
)
.
exists
(),
'skipping check (not a git repository)'
assert
not
is_docker
(),
'skipping check (Docker image)'
assert
check_online
(),
'skipping check (offline)'
cmd
=
'git fetch && git config --get remote.origin.url'
url
=
check_output
(
cmd
,
shell
=
True
,
timeout
=
5
)
.
decode
()
.
strip
()
.
rstrip
(
'.git'
)
# git fetch
branch
=
check_output
(
'git rev-parse --abbrev-ref HEAD'
,
shell
=
True
)
.
decode
()
.
strip
()
# checked out
n
=
int
(
check_output
(
f
'git rev-list {branch}..origin/master --count'
,
shell
=
True
))
# commits behind
if
n
>
0
:
s
=
f
"⚠️ WARNING: code is out of date by {n} commit{'s' * (n > 1)}. "
\
f
"Use 'git pull' to update or 'git clone {url}' to download latest."
else
:
s
=
f
'up to date with {url} ✅'
print
(
emojis
(
s
))
# emoji-safe
except
Exception
as
e
:
print
(
f
'{e}{err_msg}'
)
assert
Path
(
'.git'
)
.
exists
(),
'skipping check (not a git repository)'
+
msg
assert
not
is_docker
(),
'skipping check (Docker image)'
+
msg
assert
check_online
(),
'skipping check (offline)'
+
msg
cmd
=
'git fetch && git config --get remote.origin.url'
url
=
check_output
(
cmd
,
shell
=
True
,
timeout
=
5
)
.
decode
()
.
strip
()
.
rstrip
(
'.git'
)
# git fetch
branch
=
check_output
(
'git rev-parse --abbrev-ref HEAD'
,
shell
=
True
)
.
decode
()
.
strip
()
# checked out
n
=
int
(
check_output
(
f
'git rev-list {branch}..origin/master --count'
,
shell
=
True
))
# commits behind
if
n
>
0
:
s
=
f
"⚠️ WARNING: code is out of date by {n} commit{'s' * (n > 1)}. "
\
f
"Use 'git pull' to update or 'git clone {url}' to download latest."
else
:
s
=
f
'up to date with {url} ✅'
print
(
emojis
(
s
))
# emoji-safe
def
check_python
(
minimum
=
'3.6.2'
):
...
...
@@ -148,15 +158,14 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals
assert
result
,
f
'{name}{minimum} required by YOLOv5, but {name}{current} is currently installed'
@try_except
def
check_requirements
(
requirements
=
'requirements.txt'
,
exclude
=
()):
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
prefix
=
colorstr
(
'red'
,
'bold'
,
'requirements:'
)
check_python
()
# check python version
if
isinstance
(
requirements
,
(
str
,
Path
)):
# requirements.txt file
file
=
Path
(
requirements
)
if
not
file
.
exists
():
print
(
f
"{prefix} {file.resolve()} not found, check failed."
)
return
assert
file
.
exists
(),
f
"{prefix} {file.resolve()} not found, check failed."
requirements
=
[
f
'{x.name}{x.specifier}'
for
x
in
pkg
.
parse_requirements
(
file
.
open
())
if
x
.
name
not
in
exclude
]
else
:
# list or tuple of packages
requirements
=
[
x
for
x
in
requirements
if
x
not
in
exclude
]
...
...
@@ -178,7 +187,7 @@ def check_requirements(requirements='requirements.txt', exclude=()):
source
=
file
.
resolve
()
if
'file'
in
locals
()
else
requirements
s
=
f
"{prefix} {n} package{'s' * (n > 1)} updated per {source}
\n
"
\
f
"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}
\n
"
print
(
emojis
(
s
))
# emoji-safe
print
(
emojis
(
s
))
def
check_img_size
(
img_size
,
s
=
32
,
floor
=
0
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论