Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
886b9841
Unverified
提交
886b9841
authored
8月 06, 2020
作者:
NanoCode012
提交者:
GitHub
8月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Multi-Node support for DDP Training (#504)
* Add support for multi-node DDP * Remove local_rank confusion * Fix spacing
上级
7eaf225d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
8 行增加
和
7 行删除
+8
-7
train.py
train.py
+8
-7
没有找到文件。
train.py
浏览文件 @
886b9841
...
@@ -62,9 +62,9 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -62,9 +62,9 @@ def train(hyp, opt, device, tb_writer=None):
best
=
wdir
+
'best.pt'
best
=
wdir
+
'best.pt'
results_file
=
log_dir
+
os
.
sep
+
'results.txt'
results_file
=
log_dir
+
os
.
sep
+
'results.txt'
epochs
,
batch_size
,
total_batch_size
,
weights
,
rank
=
\
epochs
,
batch_size
,
total_batch_size
,
weights
,
rank
=
\
opt
.
epochs
,
opt
.
batch_size
,
opt
.
total_batch_size
,
opt
.
weights
,
opt
.
local_rank
opt
.
epochs
,
opt
.
batch_size
,
opt
.
total_batch_size
,
opt
.
weights
,
opt
.
global_rank
# TODO: Use DDP logging. Only the first process is allowed to log.
# TODO: Use DDP logging. Only the first process is allowed to log.
# Save run settings
# Save run settings
with
open
(
Path
(
log_dir
)
/
'hyp.yaml'
,
'w'
)
as
f
:
with
open
(
Path
(
log_dir
)
/
'hyp.yaml'
,
'w'
)
as
f
:
yaml
.
dump
(
hyp
,
f
,
sort_keys
=
False
)
yaml
.
dump
(
hyp
,
f
,
sort_keys
=
False
)
...
@@ -184,7 +184,7 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -184,7 +184,7 @@ def train(hyp, opt, device, tb_writer=None):
# DDP mode
# DDP mode
if
cuda
and
rank
!=
-
1
:
if
cuda
and
rank
!=
-
1
:
model
=
DDP
(
model
,
device_ids
=
[
rank
],
output_device
=
rank
)
model
=
DDP
(
model
,
device_ids
=
[
opt
.
local_rank
],
output_device
=
(
opt
.
local_rank
)
)
# Trainloader
# Trainloader
dataloader
,
dataset
=
create_dataloader
(
train_path
,
imgsz
,
batch_size
,
gs
,
opt
,
hyp
=
hyp
,
augment
=
True
,
dataloader
,
dataset
=
create_dataloader
(
train_path
,
imgsz
,
batch_size
,
gs
,
opt
,
hyp
=
hyp
,
augment
=
True
,
...
@@ -441,8 +441,7 @@ if __name__ == '__main__':
...
@@ -441,8 +441,7 @@ if __name__ == '__main__':
if
last
and
not
opt
.
weights
:
if
last
and
not
opt
.
weights
:
print
(
f
'Resuming training from {last}'
)
print
(
f
'Resuming training from {last}'
)
opt
.
weights
=
last
if
opt
.
resume
and
not
opt
.
weights
else
opt
.
weights
opt
.
weights
=
last
if
opt
.
resume
and
not
opt
.
weights
else
opt
.
weights
if
opt
.
local_rank
==
-
1
or
(
"RANK"
in
os
.
environ
and
os
.
environ
[
"RANK"
]
==
"0"
):
if
opt
.
local_rank
in
[
-
1
,
0
]:
check_git_status
()
check_git_status
()
opt
.
cfg
=
check_file
(
opt
.
cfg
)
# check file
opt
.
cfg
=
check_file
(
opt
.
cfg
)
# check file
opt
.
data
=
check_file
(
opt
.
data
)
# check file
opt
.
data
=
check_file
(
opt
.
data
)
# check file
...
@@ -454,7 +453,8 @@ if __name__ == '__main__':
...
@@ -454,7 +453,8 @@ if __name__ == '__main__':
device
=
select_device
(
opt
.
device
,
batch_size
=
opt
.
batch_size
)
device
=
select_device
(
opt
.
device
,
batch_size
=
opt
.
batch_size
)
opt
.
total_batch_size
=
opt
.
batch_size
opt
.
total_batch_size
=
opt
.
batch_size
opt
.
world_size
=
1
opt
.
world_size
=
1
opt
.
global_rank
=
-
1
# DDP mode
# DDP mode
if
opt
.
local_rank
!=
-
1
:
if
opt
.
local_rank
!=
-
1
:
assert
torch
.
cuda
.
device_count
()
>
opt
.
local_rank
assert
torch
.
cuda
.
device_count
()
>
opt
.
local_rank
...
@@ -462,6 +462,7 @@ if __name__ == '__main__':
...
@@ -462,6 +462,7 @@ if __name__ == '__main__':
device
=
torch
.
device
(
'cuda'
,
opt
.
local_rank
)
device
=
torch
.
device
(
'cuda'
,
opt
.
local_rank
)
dist
.
init_process_group
(
backend
=
'nccl'
,
init_method
=
'env://'
)
# distributed backend
dist
.
init_process_group
(
backend
=
'nccl'
,
init_method
=
'env://'
)
# distributed backend
opt
.
world_size
=
dist
.
get_world_size
()
opt
.
world_size
=
dist
.
get_world_size
()
opt
.
global_rank
=
dist
.
get_rank
()
assert
opt
.
batch_size
%
opt
.
world_size
==
0
,
'--batch-size must be multiple of CUDA device count'
assert
opt
.
batch_size
%
opt
.
world_size
==
0
,
'--batch-size must be multiple of CUDA device count'
opt
.
batch_size
=
opt
.
total_batch_size
//
opt
.
world_size
opt
.
batch_size
=
opt
.
total_batch_size
//
opt
.
world_size
...
@@ -470,7 +471,7 @@ if __name__ == '__main__':
...
@@ -470,7 +471,7 @@ if __name__ == '__main__':
# Train
# Train
if
not
opt
.
evolve
:
if
not
opt
.
evolve
:
tb_writer
=
None
tb_writer
=
None
if
opt
.
loc
al_rank
in
[
-
1
,
0
]:
if
opt
.
glob
al_rank
in
[
-
1
,
0
]:
print
(
'Start Tensorboard with "tensorboard --logdir=runs", view at http://localhost:6006/'
)
print
(
'Start Tensorboard with "tensorboard --logdir=runs", view at http://localhost:6006/'
)
tb_writer
=
SummaryWriter
(
log_dir
=
increment_dir
(
'runs/exp'
,
opt
.
name
))
tb_writer
=
SummaryWriter
(
log_dir
=
increment_dir
(
'runs/exp'
,
opt
.
name
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论