Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
1bf93652
Unverified
提交
1bf93652
authored
3月 23, 2021
作者:
Ayush Chaurasia
提交者:
GitHub
3月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
W&B DDP fix (#2574)
上级
0d891c60
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
9 行增加
和
4 行删除
+9
-4
train.py
train.py
+5
-3
wandb_utils.py
utils/wandb_logging/wandb_utils.py
+4
-1
没有找到文件。
train.py
浏览文件 @
1bf93652
...
@@ -66,14 +66,16 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -66,14 +66,16 @@ def train(hyp, opt, device, tb_writer=None):
is_coco
=
opt
.
data
.
endswith
(
'coco.yaml'
)
is_coco
=
opt
.
data
.
endswith
(
'coco.yaml'
)
# Logging- Doing this before checking the dataset. Might update data_dict
# Logging- Doing this before checking the dataset. Might update data_dict
loggers
=
{
'wandb'
:
None
}
# loggers dict
if
rank
in
[
-
1
,
0
]:
if
rank
in
[
-
1
,
0
]:
opt
.
hyp
=
hyp
# add hyperparameters
opt
.
hyp
=
hyp
# add hyperparameters
run_id
=
torch
.
load
(
weights
)
.
get
(
'wandb_id'
)
if
weights
.
endswith
(
'.pt'
)
and
os
.
path
.
isfile
(
weights
)
else
None
run_id
=
torch
.
load
(
weights
)
.
get
(
'wandb_id'
)
if
weights
.
endswith
(
'.pt'
)
and
os
.
path
.
isfile
(
weights
)
else
None
wandb_logger
=
WandbLogger
(
opt
,
Path
(
opt
.
save_dir
)
.
stem
,
run_id
,
data_dict
)
wandb_logger
=
WandbLogger
(
opt
,
Path
(
opt
.
save_dir
)
.
stem
,
run_id
,
data_dict
)
loggers
[
'wandb'
]
=
wandb_logger
.
wandb
data_dict
=
wandb_logger
.
data_dict
data_dict
=
wandb_logger
.
data_dict
if
wandb_logger
.
wandb
:
if
wandb_logger
.
wandb
:
weights
,
epochs
,
hyp
=
opt
.
weights
,
opt
.
epochs
,
opt
.
hyp
# WandbLogger might update weights, epochs if resuming
weights
,
epochs
,
hyp
=
opt
.
weights
,
opt
.
epochs
,
opt
.
hyp
# WandbLogger might update weights, epochs if resuming
loggers
=
{
'wandb'
:
wandb_logger
.
wandb
}
# loggers dict
nc
=
1
if
opt
.
single_cls
else
int
(
data_dict
[
'nc'
])
# number of classes
nc
=
1
if
opt
.
single_cls
else
int
(
data_dict
[
'nc'
])
# number of classes
names
=
[
'item'
]
if
opt
.
single_cls
and
len
(
data_dict
[
'names'
])
!=
1
else
data_dict
[
'names'
]
# class names
names
=
[
'item'
]
if
opt
.
single_cls
and
len
(
data_dict
[
'names'
])
!=
1
else
data_dict
[
'names'
]
# class names
assert
len
(
names
)
==
nc
,
'
%
g names found for nc=
%
g dataset in
%
s'
%
(
len
(
names
),
nc
,
opt
.
data
)
# check
assert
len
(
names
)
==
nc
,
'
%
g names found for nc=
%
g dataset in
%
s'
%
(
len
(
names
),
nc
,
opt
.
data
)
# check
...
@@ -381,6 +383,7 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -381,6 +383,7 @@ def train(hyp, opt, device, tb_writer=None):
fi
=
fitness
(
np
.
array
(
results
)
.
reshape
(
1
,
-
1
))
# weighted combination of [P, R, mAP@.5, mAP@.5-.95]
fi
=
fitness
(
np
.
array
(
results
)
.
reshape
(
1
,
-
1
))
# weighted combination of [P, R, mAP@.5, mAP@.5-.95]
if
fi
>
best_fitness
:
if
fi
>
best_fitness
:
best_fitness
=
fi
best_fitness
=
fi
wandb_logger
.
end_epoch
(
best_result
=
best_fitness
==
fi
)
# Save model
# Save model
if
(
not
opt
.
nosave
)
or
(
final_epoch
and
not
opt
.
evolve
):
# if save
if
(
not
opt
.
nosave
)
or
(
final_epoch
and
not
opt
.
evolve
):
# if save
...
@@ -402,7 +405,6 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -402,7 +405,6 @@ def train(hyp, opt, device, tb_writer=None):
wandb_logger
.
log_model
(
wandb_logger
.
log_model
(
last
.
parent
,
opt
,
epoch
,
fi
,
best_model
=
best_fitness
==
fi
)
last
.
parent
,
opt
,
epoch
,
fi
,
best_model
=
best_fitness
==
fi
)
del
ckpt
del
ckpt
wandb_logger
.
end_epoch
(
best_result
=
best_fitness
==
fi
)
# end epoch ----------------------------------------------------------------------------------------------------
# end epoch ----------------------------------------------------------------------------------------------------
# end training
# end training
...
@@ -442,10 +444,10 @@ def train(hyp, opt, device, tb_writer=None):
...
@@ -442,10 +444,10 @@ def train(hyp, opt, device, tb_writer=None):
wandb_logger
.
wandb
.
log_artifact
(
str
(
final
),
type
=
'model'
,
wandb_logger
.
wandb
.
log_artifact
(
str
(
final
),
type
=
'model'
,
name
=
'run_'
+
wandb_logger
.
wandb_run
.
id
+
'_model'
,
name
=
'run_'
+
wandb_logger
.
wandb_run
.
id
+
'_model'
,
aliases
=
[
'last'
,
'best'
,
'stripped'
])
aliases
=
[
'last'
,
'best'
,
'stripped'
])
wandb_logger
.
finish_run
()
else
:
else
:
dist
.
destroy_process_group
()
dist
.
destroy_process_group
()
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
wandb_logger
.
finish_run
()
return
results
return
results
...
...
utils/wandb_logging/wandb_utils.py
浏览文件 @
1bf93652
...
@@ -16,9 +16,9 @@ from utils.general import colorstr, xywh2xyxy, check_dataset
...
@@ -16,9 +16,9 @@ from utils.general import colorstr, xywh2xyxy, check_dataset
try
:
try
:
import
wandb
import
wandb
from
wandb
import
init
,
finish
except
ImportError
:
except
ImportError
:
wandb
=
None
wandb
=
None
print
(
f
"{colorstr('wandb: ')}Install Weights & Biases for YOLOv5 logging with 'pip install wandb' (recommended)"
)
WANDB_ARTIFACT_PREFIX
=
'wandb-artifact://'
WANDB_ARTIFACT_PREFIX
=
'wandb-artifact://'
...
@@ -71,6 +71,9 @@ class WandbLogger():
...
@@ -71,6 +71,9 @@ class WandbLogger():
self
.
data_dict
=
self
.
setup_training
(
opt
,
data_dict
)
self
.
data_dict
=
self
.
setup_training
(
opt
,
data_dict
)
if
self
.
job_type
==
'Dataset Creation'
:
if
self
.
job_type
==
'Dataset Creation'
:
self
.
data_dict
=
self
.
check_and_upload_dataset
(
opt
)
self
.
data_dict
=
self
.
check_and_upload_dataset
(
opt
)
else
:
print
(
f
"{colorstr('wandb: ')}Install Weights & Biases for YOLOv5 logging with 'pip install wandb' (recommended)"
)
def
check_and_upload_dataset
(
self
,
opt
):
def
check_and_upload_dataset
(
self
,
opt
):
assert
wandb
,
'Install wandb to upload dataset'
assert
wandb
,
'Install wandb to upload dataset'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论