Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
16f68344
提交
16f68344
authored
7月 08, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update train.py and experimental.py
上级
1b9e28e7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
13 行删除
+14
-13
experimental.py
models/experimental.py
+4
-1
train.py
train.py
+10
-12
没有找到文件。
models/experimental.py
浏览文件 @
16f68344
...
@@ -119,7 +119,10 @@ class Ensemble(nn.ModuleList):
...
@@ -119,7 +119,10 @@ class Ensemble(nn.ModuleList):
y
=
[]
y
=
[]
for
module
in
self
:
for
module
in
self
:
y
.
append
(
module
(
x
,
augment
)[
0
])
y
.
append
(
module
(
x
,
augment
)[
0
])
return
torch
.
cat
(
y
,
1
),
None
# ensembled inference output, train output
# y = torch.stack(y).max(0)[0] # max ensemble
# y = torch.cat(y, 1) # nms ensemble
y
=
torch
.
stack
(
y
)
.
mean
(
0
)
# mean ensemble
return
y
,
None
# inference, train output
def
attempt_load
(
weights
,
map_location
=
None
):
def
attempt_load
(
weights
,
map_location
=
None
):
...
...
train.py
浏览文件 @
16f68344
...
@@ -101,11 +101,13 @@ def train(hyp):
...
@@ -101,11 +101,13 @@ def train(hyp):
optim
.
SGD
(
pg0
,
lr
=
hyp
[
'lr0'
],
momentum
=
hyp
[
'momentum'
],
nesterov
=
True
)
optim
.
SGD
(
pg0
,
lr
=
hyp
[
'lr0'
],
momentum
=
hyp
[
'momentum'
],
nesterov
=
True
)
optimizer
.
add_param_group
({
'params'
:
pg1
,
'weight_decay'
:
hyp
[
'weight_decay'
]})
# add pg1 with weight_decay
optimizer
.
add_param_group
({
'params'
:
pg1
,
'weight_decay'
:
hyp
[
'weight_decay'
]})
# add pg1 with weight_decay
optimizer
.
add_param_group
({
'params'
:
pg2
})
# add pg2 (biases)
optimizer
.
add_param_group
({
'params'
:
pg2
})
# add pg2 (biases)
print
(
'Optimizer groups:
%
g .bias,
%
g conv.weight,
%
g other'
%
(
len
(
pg2
),
len
(
pg1
),
len
(
pg0
)))
del
pg0
,
pg1
,
pg2
# Scheduler https://arxiv.org/pdf/1812.01187.pdf
# Scheduler https://arxiv.org/pdf/1812.01187.pdf
lf
=
lambda
x
:
(((
1
+
math
.
cos
(
x
*
math
.
pi
/
epochs
))
/
2
)
**
1.0
)
*
0.9
+
0.1
# cosine
lf
=
lambda
x
:
(((
1
+
math
.
cos
(
x
*
math
.
pi
/
epochs
))
/
2
)
**
1.0
)
*
0.9
+
0.1
# cosine
scheduler
=
lr_scheduler
.
LambdaLR
(
optimizer
,
lr_lambda
=
lf
)
scheduler
=
lr_scheduler
.
LambdaLR
(
optimizer
,
lr_lambda
=
lf
)
print
(
'Optimizer groups:
%
g .bias,
%
g conv.weight,
%
g other'
%
(
len
(
pg2
),
len
(
pg1
),
len
(
pg0
)))
# plot_lr_scheduler(optimizer, scheduler, epochs)
del
pg0
,
pg1
,
pg2
# Load Model
# Load Model
google_utils
.
attempt_download
(
weights
)
google_utils
.
attempt_download
(
weights
)
...
@@ -147,12 +149,7 @@ def train(hyp):
...
@@ -147,12 +149,7 @@ def train(hyp):
if
mixed_precision
:
if
mixed_precision
:
model
,
optimizer
=
amp
.
initialize
(
model
,
optimizer
,
opt_level
=
'O1'
,
verbosity
=
0
)
model
,
optimizer
=
amp
.
initialize
(
model
,
optimizer
,
opt_level
=
'O1'
,
verbosity
=
0
)
# Distributed training
scheduler
.
last_epoch
=
start_epoch
-
1
# do not move
# https://discuss.pytorch.org/t/a-problem-occured-when-resuming-an-optimizer/28822
# plot_lr_scheduler(optimizer, scheduler, epochs)
# Initialize distributed training
if
device
.
type
!=
'cpu'
and
torch
.
cuda
.
device_count
()
>
1
and
torch
.
distributed
.
is_available
():
if
device
.
type
!=
'cpu'
and
torch
.
cuda
.
device_count
()
>
1
and
torch
.
distributed
.
is_available
():
dist
.
init_process_group
(
backend
=
'nccl'
,
# distributed backend
dist
.
init_process_group
(
backend
=
'nccl'
,
# distributed backend
init_method
=
'tcp://127.0.0.1:9999'
,
# init method
init_method
=
'tcp://127.0.0.1:9999'
,
# init method
...
@@ -198,9 +195,10 @@ def train(hyp):
...
@@ -198,9 +195,10 @@ def train(hyp):
# Start training
# Start training
t0
=
time
.
time
()
t0
=
time
.
time
()
nb
=
len
(
dataloader
)
# number of batches
nb
=
len
(
dataloader
)
# number of batches
n
_burn
=
max
(
3
*
nb
,
1e3
)
# burn-in
iterations, max(3 epochs, 1k iterations)
n
w
=
max
(
3
*
nb
,
1e3
)
# number of warmup
iterations, max(3 epochs, 1k iterations)
maps
=
np
.
zeros
(
nc
)
# mAP per class
maps
=
np
.
zeros
(
nc
)
# mAP per class
results
=
(
0
,
0
,
0
,
0
,
0
,
0
,
0
)
# 'P', 'R', 'mAP', 'F1', 'val GIoU', 'val Objectness', 'val Classification'
results
=
(
0
,
0
,
0
,
0
,
0
,
0
,
0
)
# 'P', 'R', 'mAP', 'F1', 'val GIoU', 'val Objectness', 'val Classification'
scheduler
.
last_epoch
=
start_epoch
-
1
# do not move
print
(
'Image sizes
%
g train,
%
g test'
%
(
imgsz
,
imgsz_test
))
print
(
'Image sizes
%
g train,
%
g test'
%
(
imgsz
,
imgsz_test
))
print
(
'Using
%
g dataloader workers'
%
dataloader
.
num_workers
)
print
(
'Using
%
g dataloader workers'
%
dataloader
.
num_workers
)
print
(
'Starting training for
%
g epochs...'
%
epochs
)
print
(
'Starting training for
%
g epochs...'
%
epochs
)
...
@@ -225,9 +223,9 @@ def train(hyp):
...
@@ -225,9 +223,9 @@ def train(hyp):
ni
=
i
+
nb
*
epoch
# number integrated batches (since train start)
ni
=
i
+
nb
*
epoch
# number integrated batches (since train start)
imgs
=
imgs
.
to
(
device
)
.
float
()
/
255.0
# uint8 to float32, 0 - 255 to 0.0 - 1.0
imgs
=
imgs
.
to
(
device
)
.
float
()
/
255.0
# uint8 to float32, 0 - 255 to 0.0 - 1.0
#
Burn-in
#
Warmup
if
ni
<=
n
_burn
:
if
ni
<=
n
w
:
xi
=
[
0
,
n
_burn
]
# x interp
xi
=
[
0
,
n
w
]
# x interp
# model.gr = np.interp(ni, xi, [0.0, 1.0]) # giou loss ratio (obj_loss = 1.0 or giou)
# model.gr = np.interp(ni, xi, [0.0, 1.0]) # giou loss ratio (obj_loss = 1.0 or giou)
accumulate
=
max
(
1
,
np
.
interp
(
ni
,
xi
,
[
1
,
nbs
/
batch_size
])
.
round
())
accumulate
=
max
(
1
,
np
.
interp
(
ni
,
xi
,
[
1
,
nbs
/
batch_size
])
.
round
())
for
j
,
x
in
enumerate
(
optimizer
.
param_groups
):
for
j
,
x
in
enumerate
(
optimizer
.
param_groups
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论