Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
20049be2
Unverified
提交
20049be2
authored
8月 18, 2022
作者:
Glenn Jocher
提交者:
GitHub
8月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EMA FP32 assert classification bug fix (#9016)
* Return EMA float on classification val * verbose val fix * EMA check
上级
529aafd7
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
14 行增加
和
11 行删除
+14
-11
val.py
classify/val.py
+2
-1
export.py
export.py
+1
-1
experimental.py
models/experimental.py
+7
-3
train.py
train.py
+1
-2
torch_utils.py
utils/torch_utils.py
+3
-4
没有找到文件。
classify/val.py
浏览文件 @
20049be2
...
...
@@ -116,7 +116,7 @@ def run(
if
verbose
:
# all classes
LOGGER
.
info
(
f
"{'Class':>24}{'Images':>12}{'top1_acc':>12}{'top5_acc':>12}"
)
LOGGER
.
info
(
f
"{'all':>24}{targets.shape[0]:>12}{top1:>12.3g}{top5:>12.3g}"
)
for
i
,
c
in
enumerate
(
model
.
names
):
for
i
,
c
in
model
.
names
.
items
(
):
aci
=
acc
[
targets
==
i
]
top1i
,
top5i
=
aci
.
mean
(
0
)
.
tolist
()
LOGGER
.
info
(
f
"{c:>24}{aci.shape[0]:>12}{top1i:>12.3g}{top5i:>12.3g}"
)
...
...
@@ -127,6 +127,7 @@ def run(
LOGGER
.
info
(
f
'Speed:
%.1
fms pre-process,
%.1
fms inference,
%.1
fms post-process per image at shape {shape}'
%
t
)
LOGGER
.
info
(
f
"Results saved to {colorstr('bold', save_dir)}"
)
model
.
float
()
# for training
return
top1
,
top5
,
loss
...
...
export.py
浏览文件 @
20049be2
...
...
@@ -599,7 +599,7 @@ def parse_opt():
parser
.
add_argument
(
'--conf-thres'
,
type
=
float
,
default
=
0.25
,
help
=
'TF.js NMS: confidence threshold'
)
parser
.
add_argument
(
'--include'
,
nargs
=
'+'
,
default
=
[
'torchscript'
,
'onnx'
],
default
=
[
'torchscript'
],
help
=
'torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs'
)
opt
=
parser
.
parse_args
()
print_args
(
vars
(
opt
))
...
...
models/experimental.py
浏览文件 @
20049be2
...
...
@@ -8,7 +8,6 @@ import numpy as np
import
torch
import
torch.nn
as
nn
from
models.common
import
Conv
from
utils.downloads
import
attempt_download
...
...
@@ -79,11 +78,16 @@ def attempt_load(weights, device=None, inplace=True, fuse=True):
for
w
in
weights
if
isinstance
(
weights
,
list
)
else
[
weights
]:
ckpt
=
torch
.
load
(
attempt_download
(
w
),
map_location
=
'cpu'
)
# load
ckpt
=
(
ckpt
.
get
(
'ema'
)
or
ckpt
[
'model'
])
.
to
(
device
)
.
float
()
# FP32 model
# Model compatibility updates
if
not
hasattr
(
ckpt
,
'stride'
):
ckpt
.
stride
=
torch
.
tensor
([
32.
])
# compatibility update for ResNet etc.
ckpt
.
stride
=
torch
.
tensor
([
32.
])
if
hasattr
(
ckpt
,
'names'
)
and
isinstance
(
ckpt
.
names
,
(
list
,
tuple
)):
ckpt
.
names
=
dict
(
enumerate
(
ckpt
.
names
))
# convert to dict
model
.
append
(
ckpt
.
fuse
()
.
eval
()
if
fuse
and
hasattr
(
ckpt
,
'fuse'
)
else
ckpt
.
eval
())
# model in eval mode
#
C
ompatibility updates
#
Module c
ompatibility updates
for
m
in
model
.
modules
():
t
=
type
(
m
)
if
t
in
(
nn
.
Hardswish
,
nn
.
LeakyReLU
,
nn
.
ReLU
,
nn
.
ReLU6
,
nn
.
SiLU
,
Detect
,
Model
):
...
...
train.py
浏览文件 @
20049be2
...
...
@@ -107,8 +107,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
data_dict
=
data_dict
or
check_dataset
(
data
)
# check if None
train_path
,
val_path
=
data_dict
[
'train'
],
data_dict
[
'val'
]
nc
=
1
if
single_cls
else
int
(
data_dict
[
'nc'
])
# number of classes
names
=
[
'item'
]
if
single_cls
and
len
(
data_dict
[
'names'
])
!=
1
else
data_dict
[
'names'
]
# class names
assert
len
(
names
)
==
nc
,
f
'{len(names)} names found for nc={nc} dataset in {data}'
# check
names
=
{
0
:
'item'
}
if
single_cls
and
len
(
data_dict
[
'names'
])
!=
1
else
data_dict
[
'names'
]
# class names
is_coco
=
isinstance
(
val_path
,
str
)
and
val_path
.
endswith
(
'coco/val2017.txt'
)
# COCO dataset
# Model
...
...
utils/torch_utils.py
浏览文件 @
20049be2
...
...
@@ -408,8 +408,6 @@ class ModelEMA:
def
__init__
(
self
,
model
,
decay
=
0.9999
,
tau
=
2000
,
updates
=
0
):
# Create EMA
self
.
ema
=
deepcopy
(
de_parallel
(
model
))
.
eval
()
# FP32 EMA
# if next(model.parameters()).device.type != 'cpu':
# self.ema.half() # FP16 EMA
self
.
updates
=
updates
# number of EMA updates
self
.
decay
=
lambda
x
:
decay
*
(
1
-
math
.
exp
(
-
x
/
tau
))
# decay exponential ramp (to help early epochs)
for
p
in
self
.
ema
.
parameters
():
...
...
@@ -423,9 +421,10 @@ class ModelEMA:
msd
=
de_parallel
(
model
)
.
state_dict
()
# model state_dict
for
k
,
v
in
self
.
ema
.
state_dict
()
.
items
():
if
v
.
dtype
.
is_floating_point
:
if
v
.
dtype
.
is_floating_point
:
# true for FP16 and FP32
v
*=
d
v
+=
(
1
-
d
)
*
msd
[
k
]
.
detach
()
v
+=
(
1
-
d
)
*
msd
[
k
]
assert
v
.
dtype
==
msd
[
k
]
.
dtype
==
torch
.
float32
,
f
'EMA {v.dtype} and model {msd[k]} must be updated in FP32'
def
update_attr
(
self
,
model
,
include
=
(),
exclude
=
(
'process_group'
,
'reducer'
)):
# Update EMA attributes
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论