Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
54874518
Unverified
提交
54874518
authored
9月 05, 2021
作者:
Glenn Jocher
提交者:
GitHub
9月 05, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EarlyStopper updates (#4679)
上级
f64fab58
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
8 行增加
和
5 行删除
+8
-5
train.py
train.py
+3
-3
torch_utils.py
utils/torch_utils.py
+5
-2
没有找到文件。
train.py
浏览文件 @
54874518
...
@@ -344,7 +344,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
...
@@ -344,7 +344,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
# mAP
# mAP
callbacks
.
on_train_epoch_end
(
epoch
=
epoch
)
callbacks
.
on_train_epoch_end
(
epoch
=
epoch
)
ema
.
update_attr
(
model
,
include
=
[
'yaml'
,
'nc'
,
'hyp'
,
'names'
,
'stride'
,
'class_weights'
])
ema
.
update_attr
(
model
,
include
=
[
'yaml'
,
'nc'
,
'hyp'
,
'names'
,
'stride'
,
'class_weights'
])
final_epoch
=
epoch
+
1
==
epochs
final_epoch
=
(
epoch
+
1
==
epochs
)
or
stopper
.
possible_stop
if
not
noval
or
final_epoch
:
# Calculate mAP
if
not
noval
or
final_epoch
:
# Calculate mAP
results
,
maps
,
_
=
val
.
run
(
data_dict
,
results
,
maps
,
_
=
val
.
run
(
data_dict
,
batch_size
=
batch_size
//
WORLD_SIZE
*
2
,
batch_size
=
batch_size
//
WORLD_SIZE
*
2
,
...
@@ -384,7 +384,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
...
@@ -384,7 +384,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
callbacks
.
on_model_save
(
last
,
epoch
,
final_epoch
,
best_fitness
,
fi
)
callbacks
.
on_model_save
(
last
,
epoch
,
final_epoch
,
best_fitness
,
fi
)
# Stop Single-GPU
# Stop Single-GPU
if
stopper
(
epoch
=
epoch
,
fitness
=
fi
):
if
RANK
==
-
1
and
stopper
(
epoch
=
epoch
,
fitness
=
fi
):
break
break
# Stop DDP TODO: known issues shttps://github.com/ultralytics/yolov5/pull/4576
# Stop DDP TODO: known issues shttps://github.com/ultralytics/yolov5/pull/4576
...
@@ -462,7 +462,7 @@ def parse_opt(known=False):
...
@@ -462,7 +462,7 @@ def parse_opt(known=False):
parser
.
add_argument
(
'--artifact_alias'
,
type
=
str
,
default
=
"latest"
,
help
=
'version of dataset artifact to be used'
)
parser
.
add_argument
(
'--artifact_alias'
,
type
=
str
,
default
=
"latest"
,
help
=
'version of dataset artifact to be used'
)
parser
.
add_argument
(
'--local_rank'
,
type
=
int
,
default
=-
1
,
help
=
'DDP parameter, do not modify'
)
parser
.
add_argument
(
'--local_rank'
,
type
=
int
,
default
=-
1
,
help
=
'DDP parameter, do not modify'
)
parser
.
add_argument
(
'--freeze'
,
type
=
int
,
default
=
0
,
help
=
'Number of layers to freeze. backbone=10, all=24'
)
parser
.
add_argument
(
'--freeze'
,
type
=
int
,
default
=
0
,
help
=
'Number of layers to freeze. backbone=10, all=24'
)
parser
.
add_argument
(
'--patience'
,
type
=
int
,
default
=
30
,
help
=
'EarlyStopping patience (epochs
)'
)
parser
.
add_argument
(
'--patience'
,
type
=
int
,
default
=
100
,
help
=
'EarlyStopping patience (epochs without improvement
)'
)
opt
=
parser
.
parse_known_args
()[
0
]
if
known
else
parser
.
parse_args
()
opt
=
parser
.
parse_known_args
()[
0
]
if
known
else
parser
.
parse_args
()
return
opt
return
opt
...
...
utils/torch_utils.py
浏览文件 @
54874518
...
@@ -298,13 +298,16 @@ class EarlyStopping:
...
@@ -298,13 +298,16 @@ class EarlyStopping:
def
__init__
(
self
,
patience
=
30
):
def
__init__
(
self
,
patience
=
30
):
self
.
best_fitness
=
0.0
# i.e. mAP
self
.
best_fitness
=
0.0
# i.e. mAP
self
.
best_epoch
=
0
self
.
best_epoch
=
0
self
.
patience
=
patience
# epochs to wait after fitness stops improving to stop
self
.
patience
=
patience
or
float
(
'inf'
)
# epochs to wait after fitness stops improving to stop
self
.
possible_stop
=
False
# possible stop may occur next epoch
def
__call__
(
self
,
epoch
,
fitness
):
def
__call__
(
self
,
epoch
,
fitness
):
if
fitness
>=
self
.
best_fitness
:
# >= 0 to allow for early zero-fitness stage of training
if
fitness
>=
self
.
best_fitness
:
# >= 0 to allow for early zero-fitness stage of training
self
.
best_epoch
=
epoch
self
.
best_epoch
=
epoch
self
.
best_fitness
=
fitness
self
.
best_fitness
=
fitness
stop
=
(
epoch
-
self
.
best_epoch
)
>=
self
.
patience
# stop training if patience exceeded
delta
=
epoch
-
self
.
best_epoch
# epochs without improvement
self
.
possible_stop
=
delta
>=
(
self
.
patience
-
1
)
# possible stop may occur next epoch
stop
=
delta
>=
self
.
patience
# stop training if patience exceeded
if
stop
:
if
stop
:
LOGGER
.
info
(
f
'EarlyStopping patience {self.patience} exceeded, stopping training.'
)
LOGGER
.
info
(
f
'EarlyStopping patience {self.patience} exceeded, stopping training.'
)
return
stop
return
stop
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论