Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
ecc2c7ba
Unverified
提交
ecc2c7ba
authored
3月 22, 2022
作者:
Glenn Jocher
提交者:
GitHub
3月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove named arguments where possible (#7105)
* Remove named arguments where possible Speed improvements. * Update yolo.py * Update yolo.py * Update yolo.py
上级
6134ec5d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
12 行增加
和
12 行删除
+12
-12
common.py
models/common.py
+7
-7
yolo.py
models/yolo.py
+5
-5
没有找到文件。
models/common.py
浏览文件 @
ecc2c7ba
...
...
@@ -121,7 +121,7 @@ class BottleneckCSP(nn.Module):
def
forward
(
self
,
x
):
y1
=
self
.
cv3
(
self
.
m
(
self
.
cv1
(
x
)))
y2
=
self
.
cv2
(
x
)
return
self
.
cv4
(
self
.
act
(
self
.
bn
(
torch
.
cat
((
y1
,
y2
),
dim
=
1
))))
return
self
.
cv4
(
self
.
act
(
self
.
bn
(
torch
.
cat
((
y1
,
y2
),
1
))))
class
C3
(
nn
.
Module
):
...
...
@@ -136,7 +136,7 @@ class C3(nn.Module):
# self.m = nn.Sequential(*(CrossConv(c_, c_, 3, 1, g, 1.0, shortcut) for _ in range(n)))
def
forward
(
self
,
x
):
return
self
.
cv3
(
torch
.
cat
((
self
.
m
(
self
.
cv1
(
x
)),
self
.
cv2
(
x
)),
dim
=
1
))
return
self
.
cv3
(
torch
.
cat
((
self
.
m
(
self
.
cv1
(
x
)),
self
.
cv2
(
x
)),
1
))
class
C3TR
(
C3
):
...
...
@@ -527,7 +527,7 @@ class AutoShape(nn.Module):
p
=
next
(
self
.
model
.
parameters
())
if
self
.
pt
else
torch
.
zeros
(
1
)
# for device and type
autocast
=
self
.
amp
and
(
p
.
device
.
type
!=
'cpu'
)
# Automatic Mixed Precision (AMP) inference
if
isinstance
(
imgs
,
torch
.
Tensor
):
# torch
with
amp
.
autocast
(
enabled
=
autocast
):
with
amp
.
autocast
(
autocast
):
return
self
.
model
(
imgs
.
to
(
p
.
device
)
.
type_as
(
p
),
augment
,
profile
)
# inference
# Pre-process
...
...
@@ -550,19 +550,19 @@ class AutoShape(nn.Module):
shape1
.
append
([
y
*
g
for
y
in
s
])
imgs
[
i
]
=
im
if
im
.
data
.
contiguous
else
np
.
ascontiguousarray
(
im
)
# update
shape1
=
[
make_divisible
(
x
,
self
.
stride
)
if
self
.
pt
else
size
for
x
in
np
.
array
(
shape1
)
.
max
(
0
)]
# inf shape
x
=
[
letterbox
(
im
,
new_shape
=
shape1
,
auto
=
False
)[
0
]
for
im
in
imgs
]
# pad
x
=
[
letterbox
(
im
,
shape1
,
auto
=
False
)[
0
]
for
im
in
imgs
]
# pad
x
=
np
.
ascontiguousarray
(
np
.
array
(
x
)
.
transpose
((
0
,
3
,
1
,
2
)))
# stack and BHWC to BCHW
x
=
torch
.
from_numpy
(
x
)
.
to
(
p
.
device
)
.
type_as
(
p
)
/
255
# uint8 to fp16/32
t
.
append
(
time_sync
())
with
amp
.
autocast
(
enabled
=
autocast
):
with
amp
.
autocast
(
autocast
):
# Inference
y
=
self
.
model
(
x
,
augment
,
profile
)
# forward
t
.
append
(
time_sync
())
# Post-process
y
=
non_max_suppression
(
y
if
self
.
dmb
else
y
[
0
],
self
.
conf
,
iou_thres
=
self
.
iou
,
classes
=
self
.
classes
,
agnostic
=
self
.
agnostic
,
multi_label
=
self
.
multi_label
,
max_det
=
self
.
max_det
)
# NMS
y
=
non_max_suppression
(
y
if
self
.
dmb
else
y
[
0
],
self
.
conf
,
self
.
iou
,
self
.
classes
,
self
.
agnostic
,
self
.
multi_label
,
max_det
=
self
.
max_det
)
# NMS
for
i
in
range
(
n
):
scale_coords
(
shape1
,
y
[
i
][:,
:
4
],
shape0
[
i
])
...
...
models/yolo.py
浏览文件 @
ecc2c7ba
...
...
@@ -71,13 +71,13 @@ class Detect(nn.Module):
def
_make_grid
(
self
,
nx
=
20
,
ny
=
20
,
i
=
0
):
d
=
self
.
anchors
[
i
]
.
device
shape
=
1
,
self
.
na
,
ny
,
nx
,
2
# grid shape
if
check_version
(
torch
.
__version__
,
'1.10.0'
):
# torch>=1.10.0 meshgrid workaround for torch>=0.7 compatibility
yv
,
xv
=
torch
.
meshgrid
(
[
torch
.
arange
(
ny
,
device
=
d
),
torch
.
arange
(
nx
,
device
=
d
)]
,
indexing
=
'ij'
)
yv
,
xv
=
torch
.
meshgrid
(
torch
.
arange
(
ny
,
device
=
d
),
torch
.
arange
(
nx
,
device
=
d
)
,
indexing
=
'ij'
)
else
:
yv
,
xv
=
torch
.
meshgrid
([
torch
.
arange
(
ny
,
device
=
d
),
torch
.
arange
(
nx
,
device
=
d
)])
grid
=
torch
.
stack
((
xv
,
yv
),
2
)
.
expand
((
1
,
self
.
na
,
ny
,
nx
,
2
))
.
float
()
anchor_grid
=
(
self
.
anchors
[
i
]
.
clone
()
*
self
.
stride
[
i
])
\
.
view
((
1
,
self
.
na
,
1
,
1
,
2
))
.
expand
((
1
,
self
.
na
,
ny
,
nx
,
2
))
.
float
()
yv
,
xv
=
torch
.
meshgrid
(
torch
.
arange
(
ny
,
device
=
d
),
torch
.
arange
(
nx
,
device
=
d
))
grid
=
torch
.
stack
((
xv
,
yv
),
2
)
.
expand
(
shape
)
.
float
()
anchor_grid
=
(
self
.
anchors
[
i
]
*
self
.
stride
[
i
])
.
view
((
1
,
self
.
na
,
1
,
1
,
2
))
.
expand
(
shape
)
.
float
()
return
grid
,
anchor_grid
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论