Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
e02a189a
Unverified
提交
e02a189a
authored
7月 02, 2020
作者:
Glenn Jocher
提交者:
GitHub
7月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #245 from yxNONG/patch-2
Unify the check point of single and multi GPU
上级
13f69777
f02481c7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
9 行删除
+15
-9
train.py
train.py
+2
-2
torch_utils.py
utils/torch_utils.py
+13
-7
没有找到文件。
train.py
浏览文件 @
e02a189a
...
...
@@ -79,7 +79,6 @@ def train(hyp):
# Create model
model
=
Model
(
opt
.
cfg
)
.
to
(
device
)
assert
model
.
md
[
'nc'
]
==
nc
,
'
%
s nc=
%
g classes but
%
s nc=
%
g classes'
%
(
opt
.
data
,
nc
,
opt
.
cfg
,
model
.
md
[
'nc'
])
model
.
names
=
data_dict
[
'names'
]
# Image sizes
gs
=
int
(
max
(
model
.
stride
))
# grid size (max stride)
...
...
@@ -178,6 +177,7 @@ def train(hyp):
model
.
hyp
=
hyp
# attach hyperparameters to model
model
.
gr
=
1.0
# giou loss ratio (obj_loss = 1.0 or giou)
model
.
class_weights
=
labels_to_class_weights
(
dataset
.
labels
,
nc
)
.
to
(
device
)
# attach class weights
model
.
names
=
data_dict
[
'names'
]
# Class frequency
labels
=
np
.
concatenate
(
dataset
.
labels
,
0
)
...
...
@@ -294,7 +294,7 @@ def train(hyp):
batch_size
=
batch_size
,
imgsz
=
imgsz_test
,
save_json
=
final_epoch
and
opt
.
data
.
endswith
(
os
.
sep
+
'coco.yaml'
),
model
=
ema
.
ema
,
model
=
ema
.
ema
.
module
if
hasattr
(
model
,
'module'
)
else
ema
.
ema
,
single_cls
=
opt
.
single_cls
,
dataloader
=
testloader
)
...
...
utils/torch_utils.py
浏览文件 @
e02a189a
...
...
@@ -54,6 +54,11 @@ def time_synchronized():
return
time
.
time
()
def
is_parallel
(
model
):
# is model is parallel with DP or DDP
return
type
(
model
)
in
(
nn
.
parallel
.
DataParallel
,
nn
.
parallel
.
DistributedDataParallel
)
def
initialize_weights
(
model
):
for
m
in
model
.
modules
():
t
=
type
(
m
)
...
...
@@ -111,8 +116,8 @@ def model_info(model, verbose=False):
try
:
# FLOPS
from
thop
import
profile
macs
,
_
=
profile
(
model
,
inputs
=
(
torch
.
zeros
(
1
,
3
,
480
,
640
),),
verbose
=
False
)
fs
=
',
%.1
f GFLOPS'
%
(
macs
/
1E9
*
2
)
flops
=
profile
(
deepcopy
(
model
),
inputs
=
(
torch
.
zeros
(
1
,
3
,
64
,
64
),),
verbose
=
False
)[
0
]
/
1E9
*
2
fs
=
',
%.1
f GFLOPS'
%
(
flops
*
100
)
# 640x640 FLOPS
except
:
fs
=
''
...
...
@@ -185,7 +190,7 @@ class ModelEMA:
self
.
updates
+=
1
d
=
self
.
decay
(
self
.
updates
)
with
torch
.
no_grad
():
if
type
(
model
)
in
(
nn
.
parallel
.
DataParallel
,
nn
.
parallel
.
DistributedDataParall
el
):
if
is_parallel
(
mod
el
):
msd
,
esd
=
model
.
module
.
state_dict
(),
self
.
ema
.
module
.
state_dict
()
else
:
msd
,
esd
=
model
.
state_dict
(),
self
.
ema
.
state_dict
()
...
...
@@ -196,7 +201,8 @@ class ModelEMA:
v
+=
(
1.
-
d
)
*
msd
[
k
]
.
detach
()
def
update_attr
(
self
,
model
):
# Assign attributes (which may change during training)
for
k
in
model
.
__dict__
.
keys
():
if
not
k
.
startswith
(
'_'
):
setattr
(
self
.
ema
,
k
,
getattr
(
model
,
k
))
# Update class attributes
ema
=
self
.
ema
.
module
if
is_parallel
(
model
)
else
self
.
ema
for
k
,
v
in
model
.
__dict__
.
items
():
if
not
k
.
startswith
(
'_'
)
and
k
!=
'module'
:
setattr
(
ema
,
k
,
v
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论