Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
a4e8f78c
Unverified
提交
a4e8f78c
authored
8月 31, 2021
作者:
Glenn Jocher
提交者:
GitHub
8月 31, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix 2 for Arial.ttf redownloads with hub inference (#4628)
上级
ba0f8087
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
22 行删除
+27
-22
__init__.py
utils/__init__.py
+19
-19
plots.py
utils/plots.py
+8
-3
没有找到文件。
utils/__init__.py
浏览文件 @
a4e8f78c
import
sys
#
import sys
from
pathlib
import
Path
#
from pathlib import Path
#
import
torch
#
import torch
from
PIL
import
ImageFont
#
from PIL import ImageFont
#
FILE
=
Path
(
__file__
)
.
absolute
()
#
FILE = Path(__file__).absolute()
ROOT
=
FILE
.
parents
[
1
]
# yolov5/ dir
#
ROOT = FILE.parents[1] # yolov5/ dir
if
str
(
ROOT
)
not
in
sys
.
path
:
#
if str(ROOT) not in sys.path:
sys
.
path
.
append
(
str
(
ROOT
))
# add ROOT to PATH
#
sys.path.append(str(ROOT)) # add ROOT to PATH
#
# Check YOLOv5 Annotator font
#
#
Check YOLOv5 Annotator font
font
=
'Arial.ttf'
#
font = 'Arial.ttf'
try
:
#
try:
ImageFont
.
truetype
(
font
)
#
ImageFont.truetype(font)
except
Exception
as
e
:
# download if missing
#
except Exception as e: # download if missing
url
=
"https://ultralytics.com/assets/"
+
font
#
url = "https://ultralytics.com/assets/" + font
print
(
f
'Downloading {url} to {ROOT / font}...'
)
#
print(f'Downloading {url} to {ROOT / font}...')
torch
.
hub
.
download_url_to_file
(
url
,
str
(
ROOT
/
font
))
#
torch.hub.download_url_to_file(url, str(ROOT / font))
utils/plots.py
浏览文件 @
a4e8f78c
...
@@ -23,6 +23,9 @@ from utils.metrics import fitness
...
@@ -23,6 +23,9 @@ from utils.metrics import fitness
matplotlib
.
rc
(
'font'
,
**
{
'size'
:
11
})
matplotlib
.
rc
(
'font'
,
**
{
'size'
:
11
})
matplotlib
.
use
(
'Agg'
)
# for writing to files only
matplotlib
.
use
(
'Agg'
)
# for writing to files only
FILE
=
Path
(
__file__
)
.
absolute
()
ROOT
=
FILE
.
parents
[
1
]
# yolov5/ dir
class
Colors
:
class
Colors
:
# Ultralytics color palette https://ultralytics.com/
# Ultralytics color palette https://ultralytics.com/
...
@@ -55,12 +58,14 @@ class Annotator:
...
@@ -55,12 +58,14 @@ class Annotator:
self
.
draw
=
ImageDraw
.
Draw
(
self
.
im
)
self
.
draw
=
ImageDraw
.
Draw
(
self
.
im
)
s
=
sum
(
self
.
im
.
size
)
/
2
# mean shape
s
=
sum
(
self
.
im
.
size
)
/
2
# mean shape
f
=
font_size
or
max
(
round
(
s
*
0.035
),
12
)
f
=
font_size
or
max
(
round
(
s
*
0.035
),
12
)
font
=
Path
(
font
)
# font handling
font
=
font
if
font
.
exists
()
else
(
ROOT
/
font
.
name
)
try
:
try
:
self
.
font
=
ImageFont
.
truetype
(
font
,
size
=
f
)
self
.
font
=
ImageFont
.
truetype
(
str
(
font
)
if
font
.
exists
()
else
font
.
name
,
size
=
f
)
except
Exception
as
e
:
# download if missing
except
Exception
as
e
:
# download if missing
url
=
"https://ultralytics.com/assets/"
+
font
url
=
"https://ultralytics.com/assets/"
+
font
.
name
print
(
f
'Downloading {url} to {font}...'
)
print
(
f
'Downloading {url} to {font}...'
)
torch
.
hub
.
download_url_to_file
(
url
,
font
)
torch
.
hub
.
download_url_to_file
(
url
,
str
(
font
)
)
self
.
font
=
ImageFont
.
truetype
(
font
,
size
=
f
)
self
.
font
=
ImageFont
.
truetype
(
font
,
size
=
f
)
self
.
fh
=
self
.
font
.
getsize
(
'a'
)[
1
]
-
3
# font height
self
.
fh
=
self
.
font
.
getsize
(
'a'
)[
1
]
-
3
# font height
else
:
# use cv2
else
:
# use cv2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论