Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
8aa2085a
Unverified
提交
8aa2085a
authored
5月 15, 2022
作者:
Glenn Jocher
提交者:
GitHub
5月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor modules (#7823)
上级
f0007141
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
17 行增加
和
23 行删除
+17
-23
experimental.py
models/experimental.py
+10
-14
tf.py
models/tf.py
+6
-8
yolo.py
models/yolo.py
+1
-1
没有找到文件。
models/experimental.py
浏览文件 @
8aa2085a
...
@@ -78,9 +78,7 @@ class Ensemble(nn.ModuleList):
...
@@ -78,9 +78,7 @@ class Ensemble(nn.ModuleList):
super
()
.
__init__
()
super
()
.
__init__
()
def
forward
(
self
,
x
,
augment
=
False
,
profile
=
False
,
visualize
=
False
):
def
forward
(
self
,
x
,
augment
=
False
,
profile
=
False
,
visualize
=
False
):
y
=
[]
y
=
[
module
(
x
,
augment
,
profile
,
visualize
)[
0
]
for
module
in
self
]
for
module
in
self
:
y
.
append
(
module
(
x
,
augment
,
profile
,
visualize
)[
0
])
# y = torch.stack(y).max(0)[0] # max ensemble
# y = torch.stack(y).max(0)[0] # max ensemble
# y = torch.stack(y).mean(0) # mean ensemble
# y = torch.stack(y).mean(0) # mean ensemble
y
=
torch
.
cat
(
y
,
1
)
# nms ensemble
y
=
torch
.
cat
(
y
,
1
)
# nms ensemble
...
@@ -102,10 +100,9 @@ def attempt_load(weights, map_location=None, inplace=True, fuse=True):
...
@@ -102,10 +100,9 @@ def attempt_load(weights, map_location=None, inplace=True, fuse=True):
t
=
type
(
m
)
t
=
type
(
m
)
if
t
in
(
nn
.
Hardswish
,
nn
.
LeakyReLU
,
nn
.
ReLU
,
nn
.
ReLU6
,
nn
.
SiLU
,
Detect
,
Model
):
if
t
in
(
nn
.
Hardswish
,
nn
.
LeakyReLU
,
nn
.
ReLU
,
nn
.
ReLU6
,
nn
.
SiLU
,
Detect
,
Model
):
m
.
inplace
=
inplace
# torch 1.7.0 compatibility
m
.
inplace
=
inplace
# torch 1.7.0 compatibility
if
t
is
Detect
:
if
t
is
Detect
and
not
isinstance
(
m
.
anchor_grid
,
list
):
if
not
isinstance
(
m
.
anchor_grid
,
list
):
# new Detect Layer compatibility
delattr
(
m
,
'anchor_grid'
)
delattr
(
m
,
'anchor_grid'
)
setattr
(
m
,
'anchor_grid'
,
[
torch
.
zeros
(
1
)]
*
m
.
nl
)
setattr
(
m
,
'anchor_grid'
,
[
torch
.
zeros
(
1
)]
*
m
.
nl
)
elif
t
is
Conv
:
elif
t
is
Conv
:
m
.
_non_persistent_buffers_set
=
set
()
# torch 1.6.0 compatibility
m
.
_non_persistent_buffers_set
=
set
()
# torch 1.6.0 compatibility
elif
t
is
nn
.
Upsample
and
not
hasattr
(
m
,
'recompute_scale_factor'
):
elif
t
is
nn
.
Upsample
and
not
hasattr
(
m
,
'recompute_scale_factor'
):
...
@@ -113,10 +110,9 @@ def attempt_load(weights, map_location=None, inplace=True, fuse=True):
...
@@ -113,10 +110,9 @@ def attempt_load(weights, map_location=None, inplace=True, fuse=True):
if
len
(
model
)
==
1
:
if
len
(
model
)
==
1
:
return
model
[
-
1
]
# return model
return
model
[
-
1
]
# return model
else
:
print
(
f
'Ensemble created with {weights}
\n
'
)
print
(
f
'Ensemble created with {weights}
\n
'
)
for
k
in
'names'
,
'nc'
,
'yaml'
:
for
k
in
'names'
,
'nc'
,
'yaml'
:
setattr
(
model
,
k
,
getattr
(
model
[
0
],
k
))
setattr
(
model
,
k
,
getattr
(
model
[
0
],
k
))
model
.
stride
=
model
[
torch
.
argmax
(
torch
.
tensor
([
m
.
stride
.
max
()
for
m
in
model
]))
.
int
()]
.
stride
# max stride
model
.
stride
=
model
[
torch
.
argmax
(
torch
.
tensor
([
m
.
stride
.
max
()
for
m
in
model
]))
.
int
()]
.
stride
# max stride
assert
all
(
model
[
0
]
.
nc
==
m
.
nc
for
m
in
model
),
f
'Models have different class counts: {[m.nc for m in model]}'
assert
all
(
model
[
0
]
.
nc
==
m
.
nc
for
m
in
model
),
f
'Models have different class counts: {[m.nc for m in model]}'
return
model
# return ensemble
return
model
# return ensemble
models/tf.py
浏览文件 @
8aa2085a
...
@@ -362,7 +362,7 @@ class TFModel:
...
@@ -362,7 +362,7 @@ class TFModel:
conf_thres
=
0.25
):
conf_thres
=
0.25
):
y
=
[]
# outputs
y
=
[]
# outputs
x
=
inputs
x
=
inputs
for
i
,
m
in
enumerate
(
self
.
model
.
layers
)
:
for
m
in
self
.
model
.
layers
:
if
m
.
f
!=
-
1
:
# if not from previous layer
if
m
.
f
!=
-
1
:
# if not from previous layer
x
=
y
[
m
.
f
]
if
isinstance
(
m
.
f
,
int
)
else
[
x
if
j
==
-
1
else
y
[
j
]
for
j
in
m
.
f
]
# from earlier layers
x
=
y
[
m
.
f
]
if
isinstance
(
m
.
f
,
int
)
else
[
x
if
j
==
-
1
else
y
[
j
]
for
j
in
m
.
f
]
# from earlier layers
...
@@ -377,7 +377,6 @@ class TFModel:
...
@@ -377,7 +377,6 @@ class TFModel:
scores
=
probs
*
classes
scores
=
probs
*
classes
if
agnostic_nms
:
if
agnostic_nms
:
nms
=
AgnosticNMS
()((
boxes
,
classes
,
scores
),
topk_all
,
iou_thres
,
conf_thres
)
nms
=
AgnosticNMS
()((
boxes
,
classes
,
scores
),
topk_all
,
iou_thres
,
conf_thres
)
return
nms
,
x
[
1
]
else
:
else
:
boxes
=
tf
.
expand_dims
(
boxes
,
2
)
boxes
=
tf
.
expand_dims
(
boxes
,
2
)
nms
=
tf
.
image
.
combined_non_max_suppression
(
boxes
,
nms
=
tf
.
image
.
combined_non_max_suppression
(
boxes
,
...
@@ -387,8 +386,7 @@ class TFModel:
...
@@ -387,8 +386,7 @@ class TFModel:
iou_thres
,
iou_thres
,
conf_thres
,
conf_thres
,
clip_boxes
=
False
)
clip_boxes
=
False
)
return
nms
,
x
[
1
]
return
nms
,
x
[
1
]
return
x
[
0
]
# output only first tensor [1,6300,85] = [xywh, conf, class0, class1, ...]
return
x
[
0
]
# output only first tensor [1,6300,85] = [xywh, conf, class0, class1, ...]
# x = x[0][0] # [x(1,6300,85), ...] to x(6300,85)
# x = x[0][0] # [x(1,6300,85), ...] to x(6300,85)
# xywh = x[..., :4] # x(6300,4) boxes
# xywh = x[..., :4] # x(6300,4) boxes
...
@@ -444,10 +442,10 @@ class AgnosticNMS(keras.layers.Layer):
...
@@ -444,10 +442,10 @@ class AgnosticNMS(keras.layers.Layer):
def
representative_dataset_gen
(
dataset
,
ncalib
=
100
):
def
representative_dataset_gen
(
dataset
,
ncalib
=
100
):
# Representative dataset generator for use with converter.representative_dataset, returns a generator of np arrays
# Representative dataset generator for use with converter.representative_dataset, returns a generator of np arrays
for
n
,
(
path
,
img
,
im0s
,
vid_cap
,
string
)
in
enumerate
(
dataset
):
for
n
,
(
path
,
img
,
im0s
,
vid_cap
,
string
)
in
enumerate
(
dataset
):
i
nput
=
np
.
transpose
(
img
,
[
1
,
2
,
0
])
i
m
=
np
.
transpose
(
img
,
[
1
,
2
,
0
])
i
nput
=
np
.
expand_dims
(
input
,
axis
=
0
)
.
astype
(
np
.
float32
)
i
m
=
np
.
expand_dims
(
im
,
axis
=
0
)
.
astype
(
np
.
float32
)
i
nput
/=
255
i
m
/=
255
yield
[
i
nput
]
yield
[
i
m
]
if
n
>=
ncalib
:
if
n
>=
ncalib
:
break
break
...
...
models/yolo.py
浏览文件 @
8aa2085a
...
@@ -197,7 +197,7 @@ class Model(nn.Module):
...
@@ -197,7 +197,7 @@ class Model(nn.Module):
m
(
x
.
copy
()
if
c
else
x
)
m
(
x
.
copy
()
if
c
else
x
)
dt
.
append
((
time_sync
()
-
t
)
*
100
)
dt
.
append
((
time_sync
()
-
t
)
*
100
)
if
m
==
self
.
model
[
0
]:
if
m
==
self
.
model
[
0
]:
LOGGER
.
info
(
f
"{'time (ms)':>10s} {'GFLOPs':>10s} {'params':>10s}
{'module'}
"
)
LOGGER
.
info
(
f
"{'time (ms)':>10s} {'GFLOPs':>10s} {'params':>10s}
module
"
)
LOGGER
.
info
(
f
'{dt[-1]:10.2f} {o:10.2f} {m.np:10.0f} {m.type}'
)
LOGGER
.
info
(
f
'{dt[-1]:10.2f} {o:10.2f} {m.np:10.0f} {m.type}'
)
if
c
:
if
c
:
LOGGER
.
info
(
f
"{sum(dt):10.2f} {'-':>10s} {'-':>10s} Total"
)
LOGGER
.
info
(
f
"{sum(dt):10.2f} {'-':>10s} {'-':>10s} Total"
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论