Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
1aa2b679
Unverified
提交
1aa2b679
authored
7月 02, 2020
作者:
yxNONG
提交者:
GitHub
7月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update train.py
上级
53cdaf6b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
18 行删除
+10
-18
train.py
train.py
+10
-18
没有找到文件。
train.py
浏览文件 @
1aa2b679
...
@@ -147,15 +147,6 @@ def train(hyp):
...
@@ -147,15 +147,6 @@ def train(hyp):
# https://discuss.pytorch.org/t/a-problem-occured-when-resuming-an-optimizer/28822
# https://discuss.pytorch.org/t/a-problem-occured-when-resuming-an-optimizer/28822
# plot_lr_scheduler(optimizer, scheduler, epochs)
# plot_lr_scheduler(optimizer, scheduler, epochs)
# Initialize distributed training
if
device
.
type
!=
'cpu'
and
torch
.
cuda
.
device_count
()
>
1
and
torch
.
distributed
.
is_available
():
dist
.
init_process_group
(
backend
=
'nccl'
,
# distributed backend
init_method
=
'tcp://127.0.0.1:9999'
,
# init method
world_size
=
1
,
# number of nodes
rank
=
0
)
# node rank
model
=
torch
.
nn
.
parallel
.
DistributedDataParallel
(
model
)
# pip install torch==1.4.0+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
# Trainloader
# Trainloader
dataloader
,
dataset
=
create_dataloader
(
train_path
,
imgsz
,
batch_size
,
gs
,
opt
,
dataloader
,
dataset
=
create_dataloader
(
train_path
,
imgsz
,
batch_size
,
gs
,
opt
,
hyp
=
hyp
,
augment
=
True
,
cache
=
opt
.
cache_images
,
rect
=
opt
.
rect
)
hyp
=
hyp
,
augment
=
True
,
cache
=
opt
.
cache_images
,
rect
=
opt
.
rect
)
...
@@ -173,6 +164,15 @@ def train(hyp):
...
@@ -173,6 +164,15 @@ def train(hyp):
model
.
gr
=
1.0
# giou loss ratio (obj_loss = 1.0 or giou)
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
.
class_weights
=
labels_to_class_weights
(
dataset
.
labels
,
nc
)
.
to
(
device
)
# attach class weights
model
.
names
=
data_dict
[
'names'
]
model
.
names
=
data_dict
[
'names'
]
# Initialize distributed training
if
device
.
type
!=
'cpu'
and
torch
.
cuda
.
device_count
()
>
1
and
torch
.
distributed
.
is_available
():
dist
.
init_process_group
(
backend
=
'nccl'
,
# distributed backend
init_method
=
'tcp://127.0.0.1:9999'
,
# init method
world_size
=
1
,
# number of nodes
rank
=
0
)
# node rank
model
=
torch
.
nn
.
parallel
.
DistributedDataParallel
(
model
)
# pip install torch==1.4.0+cu100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html
# Class frequency
# Class frequency
labels
=
np
.
concatenate
(
dataset
.
labels
,
0
)
labels
=
np
.
concatenate
(
dataset
.
labels
,
0
)
...
@@ -289,7 +289,7 @@ def train(hyp):
...
@@ -289,7 +289,7 @@ def train(hyp):
batch_size
=
batch_size
,
batch_size
=
batch_size
,
imgsz
=
imgsz_test
,
imgsz
=
imgsz_test
,
save_json
=
final_epoch
and
opt
.
data
.
endswith
(
os
.
sep
+
'coco.yaml'
),
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
,
single_cls
=
opt
.
single_cls
,
dataloader
=
testloader
)
dataloader
=
testloader
)
...
@@ -315,14 +315,6 @@ def train(hyp):
...
@@ -315,14 +315,6 @@ def train(hyp):
# Save model
# Save model
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
:
if
hasattr
(
model
,
'module'
):
# Duplicate Model parameters for Multi-GPU save
ema
.
ema
.
module
.
nc
=
model
.
nc
# attach number of classes to model
ema
.
ema
.
module
.
hyp
=
model
.
hyp
# attach hyperparameters to model
ema
.
ema
.
module
.
gr
=
model
.
gr
=
1.0
# giou loss ratio (obj_loss = 1.0 or giou)
ema
.
ema
.
module
.
class_weights
=
model
.
class_weights
# attach class weights
ema
.
ema
.
module
.
names
=
data_dict
[
'names'
]
with
open
(
results_file
,
'r'
)
as
f
:
# create checkpoint
with
open
(
results_file
,
'r'
)
as
f
:
# create checkpoint
ckpt
=
{
'epoch'
:
epoch
,
ckpt
=
{
'epoch'
:
epoch
,
'best_fitness'
:
best_fitness
,
'best_fitness'
:
best_fitness
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论