Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
ce369053
提交
ce369053
authored
5月 30, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updates
上级
1e84a23f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
16 行增加
和
16 行删除
+16
-16
test.py
test.py
+1
-1
train.py
train.py
+15
-15
没有找到文件。
test.py
浏览文件 @
ce369053
...
@@ -256,7 +256,7 @@ if __name__ == '__main__':
...
@@ -256,7 +256,7 @@ if __name__ == '__main__':
opt
.
augment
)
opt
.
augment
)
elif
opt
.
task
==
'study'
:
# run over a range of settings and save/plot
elif
opt
.
task
==
'study'
:
# run over a range of settings and save/plot
for
weights
in
[
'yolov5s.pt'
,
'yolov5m.pt'
,
'yolovl.p
5
'
,
'yolov5x.pt'
,
'yolov3-spp.pt'
]:
for
weights
in
[
'yolov5s.pt'
,
'yolov5m.pt'
,
'yolovl.p
t
'
,
'yolov5x.pt'
,
'yolov3-spp.pt'
]:
f
=
'study_
%
s_
%
s.txt'
%
(
Path
(
opt
.
data
)
.
stem
,
Path
(
weights
)
.
stem
)
# filename to save to
f
=
'study_
%
s_
%
s.txt'
%
(
Path
(
opt
.
data
)
.
stem
,
Path
(
weights
)
.
stem
)
# filename to save to
x
=
list
(
range
(
256
,
1024
,
32
))
# x axis
x
=
list
(
range
(
256
,
1024
,
32
))
# x axis
y
=
[]
# y axis
y
=
[]
# y axis
...
...
train.py
浏览文件 @
ce369053
...
@@ -108,30 +108,30 @@ def train(hyp):
...
@@ -108,30 +108,30 @@ def train(hyp):
google_utils
.
attempt_download
(
weights
)
google_utils
.
attempt_download
(
weights
)
start_epoch
,
best_fitness
=
0
,
0.0
start_epoch
,
best_fitness
=
0
,
0.0
if
weights
.
endswith
(
'.pt'
):
# pytorch format
if
weights
.
endswith
(
'.pt'
):
# pytorch format
c
hkpt
=
torch
.
load
(
weights
,
map_location
=
device
)
c
kpt
=
torch
.
load
(
weights
,
map_location
=
device
)
# load checkpoint
# load model
# load model
try
:
try
:
c
h
kpt
[
'model'
]
=
\
ckpt
[
'model'
]
=
\
{
k
:
v
for
k
,
v
in
c
h
kpt
[
'model'
]
.
state_dict
()
.
items
()
if
model
.
state_dict
()[
k
]
.
numel
()
==
v
.
numel
()}
{
k
:
v
for
k
,
v
in
ckpt
[
'model'
]
.
state_dict
()
.
items
()
if
model
.
state_dict
()[
k
]
.
numel
()
==
v
.
numel
()}
model
.
load_state_dict
(
c
h
kpt
[
'model'
],
strict
=
False
)
model
.
load_state_dict
(
ckpt
[
'model'
],
strict
=
False
)
except
KeyError
as
e
:
except
KeyError
as
e
:
s
=
"
%
s is not compatible with
%
s. Specify --weights '' or specify a --cfg compatible with
%
s."
\
s
=
"
%
s is not compatible with
%
s. Specify --weights '' or specify a --cfg compatible with
%
s."
\
%
(
opt
.
weights
,
opt
.
cfg
,
opt
.
weights
)
%
(
opt
.
weights
,
opt
.
cfg
,
opt
.
weights
)
raise
KeyError
(
s
)
from
e
raise
KeyError
(
s
)
from
e
# load optimizer
# load optimizer
if
c
h
kpt
[
'optimizer'
]
is
not
None
:
if
ckpt
[
'optimizer'
]
is
not
None
:
optimizer
.
load_state_dict
(
c
h
kpt
[
'optimizer'
])
optimizer
.
load_state_dict
(
ckpt
[
'optimizer'
])
best_fitness
=
c
h
kpt
[
'best_fitness'
]
best_fitness
=
ckpt
[
'best_fitness'
]
# load results
# load results
if
c
h
kpt
.
get
(
'training_results'
)
is
not
None
:
if
ckpt
.
get
(
'training_results'
)
is
not
None
:
with
open
(
results_file
,
'w'
)
as
file
:
with
open
(
results_file
,
'w'
)
as
file
:
file
.
write
(
c
h
kpt
[
'training_results'
])
# write results.txt
file
.
write
(
ckpt
[
'training_results'
])
# write results.txt
start_epoch
=
c
h
kpt
[
'epoch'
]
+
1
start_epoch
=
ckpt
[
'epoch'
]
+
1
del
c
h
kpt
del
ckpt
# Mixed precision training https://github.com/NVIDIA/apex
# Mixed precision training https://github.com/NVIDIA/apex
if
mixed_precision
:
if
mixed_precision
:
...
@@ -324,17 +324,17 @@ def train(hyp):
...
@@ -324,17 +324,17 @@ def train(hyp):
save
=
(
not
opt
.
nosave
)
or
(
final_epoch
and
not
opt
.
evolve
)
save
=
(
not
opt
.
nosave
)
or
(
final_epoch
and
not
opt
.
evolve
)
if
save
:
if
save
:
with
open
(
results_file
,
'r'
)
as
f
:
# create checkpoint
with
open
(
results_file
,
'r'
)
as
f
:
# create checkpoint
c
h
kpt
=
{
'epoch'
:
epoch
,
ckpt
=
{
'epoch'
:
epoch
,
'best_fitness'
:
best_fitness
,
'best_fitness'
:
best_fitness
,
'training_results'
:
f
.
read
(),
'training_results'
:
f
.
read
(),
'model'
:
ema
.
ema
.
module
if
hasattr
(
model
,
'module'
)
else
ema
.
ema
,
'model'
:
ema
.
ema
.
module
if
hasattr
(
model
,
'module'
)
else
ema
.
ema
,
'optimizer'
:
None
if
final_epoch
else
optimizer
.
state_dict
()}
'optimizer'
:
None
if
final_epoch
else
optimizer
.
state_dict
()}
# Save last, best and delete
# Save last, best and delete
torch
.
save
(
c
h
kpt
,
last
)
torch
.
save
(
ckpt
,
last
)
if
(
best_fitness
==
fi
)
and
not
final_epoch
:
if
(
best_fitness
==
fi
)
and
not
final_epoch
:
torch
.
save
(
c
h
kpt
,
best
)
torch
.
save
(
ckpt
,
best
)
del
c
h
kpt
del
ckpt
# end epoch ----------------------------------------------------------------------------------------------------
# end epoch ----------------------------------------------------------------------------------------------------
# end training
# end training
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论