Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
e5e5ebc7
Unverified
提交
e5e5ebc7
authored
8月 29, 2021
作者:
Glenn Jocher
提交者:
GitHub
8月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto-UTF handling (#4594)
上级
de44376d
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
10 行增加
和
8 行删除
+10
-8
detect.py
detect.py
+4
-3
common.py
models/common.py
+5
-4
general.py
utils/general.py
+1
-1
没有找到文件。
detect.py
浏览文件 @
e5e5ebc7
...
...
@@ -21,9 +21,9 @@ sys.path.append(FILE.parents[0].as_posix()) # add yolov5/ to path
from
models.experimental
import
attempt_load
from
utils.datasets
import
LoadStreams
,
LoadImages
from
utils.general
import
check_img_size
,
check_requirements
,
check_imshow
,
colorstr
,
non_max_suppression
,
\
from
utils.general
import
check_img_size
,
check_requirements
,
check_imshow
,
colorstr
,
is_ascii
,
non_max_suppression
,
\
apply_classifier
,
scale_coords
,
xyxy2xywh
,
strip_optimizer
,
set_logging
,
increment_path
,
save_one_box
from
utils.plots
import
colors
,
Annotator
from
utils.plots
import
Annotator
,
colors
from
utils.torch_utils
import
select_device
,
load_classifier
,
time_sync
...
...
@@ -105,6 +105,7 @@ def run(weights='yolov5s.pt', # model.pt path(s)
output_details
=
interpreter
.
get_output_details
()
# outputs
int8
=
input_details
[
0
][
'dtype'
]
==
np
.
uint8
# is TFLite quantized uint8 model
imgsz
=
check_img_size
(
imgsz
,
s
=
stride
)
# check image size
ascii
=
is_ascii
(
names
)
# names are ascii (use PIL for UTF-8)
# Dataloader
if
webcam
:
...
...
@@ -181,7 +182,7 @@ def run(weights='yolov5s.pt', # model.pt path(s)
s
+=
'
%
gx
%
g '
%
img
.
shape
[
2
:]
# print string
gn
=
torch
.
tensor
(
im0
.
shape
)[[
1
,
0
,
1
,
0
]]
# normalization gain whwh
imc
=
im0
.
copy
()
if
save_crop
else
im0
# for save_crop
annotator
=
Annotator
(
im0
,
line_width
=
line_thickness
,
pil
=
False
)
annotator
=
Annotator
(
im0
,
line_width
=
line_thickness
,
pil
=
not
ascii
)
if
len
(
det
):
# Rescale boxes from img_size to im0 size
det
[:,
:
4
]
=
scale_coords
(
img
.
shape
[
2
:],
det
[:,
:
4
],
im0
.
shape
)
.
round
()
...
...
models/common.py
浏览文件 @
e5e5ebc7
...
...
@@ -18,9 +18,9 @@ from PIL import Image
from
torch.cuda
import
amp
from
utils.datasets
import
exif_transpose
,
letterbox
from
utils.general
import
colorstr
,
non_max_suppression
,
make_divisible
,
scale_coords
,
increment_path
,
xyxy2xywh
,
\
s
ave_one_box
from
utils.plots
import
colors
,
Annotator
from
utils.general
import
colorstr
,
increment_path
,
is_ascii
,
make_divisible
,
non_max_suppression
,
save_one_box
,
\
s
cale_coords
,
xyxy2xywh
from
utils.plots
import
Annotator
,
colors
from
utils.torch_utils
import
time_sync
LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -354,6 +354,7 @@ class Detections:
self
.
imgs
=
imgs
# list of images as numpy arrays
self
.
pred
=
pred
# list of tensors pred[0] = (xyxy, conf, cls)
self
.
names
=
names
# class names
self
.
ascii
=
is_ascii
(
names
)
# names are ascii (use PIL for UTF-8)
self
.
files
=
files
# image filenames
self
.
xyxy
=
pred
# xyxy pixels
self
.
xywh
=
[
xyxy2xywh
(
x
)
for
x
in
pred
]
# xywh pixels
...
...
@@ -371,7 +372,7 @@ class Detections:
n
=
(
pred
[:,
-
1
]
==
c
)
.
sum
()
# detections per class
str
+=
f
"{n} {self.names[int(c)]}{'s' * (n > 1)}, "
# add to string
if
show
or
save
or
render
or
crop
:
annotator
=
Annotator
(
im
,
pil
=
False
)
annotator
=
Annotator
(
im
,
pil
=
not
self
.
ascii
)
for
*
box
,
conf
,
cls
in
reversed
(
pred
):
# xyxy, confidence, class
label
=
f
'{self.names[int(cls)]} {conf:.2f}'
if
crop
:
...
...
utils/general.py
浏览文件 @
e5e5ebc7
...
...
@@ -124,7 +124,7 @@ def is_pip():
def
is_ascii
(
s
=
''
):
# Is string composed of all ASCII (no UTF) characters?
s
=
str
(
s
)
# convert
to str() in case of None, etc.
s
=
str
(
s
)
# convert
list, tuple, None, etc. to str
return
len
(
s
.
encode
()
.
decode
(
'ascii'
,
'ignore'
))
==
len
(
s
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论