Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
e189fa15
Unverified
提交
e189fa15
authored
11月 06, 2021
作者:
Glenn Jocher
提交者:
GitHub
11月 06, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
`intersect_dicts()` in hubconf.py fix (#5542)
上级
fa2344cd
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
10 行增加
和
12 行删除
+10
-12
hubconf.py
hubconf.py
+2
-3
train.py
train.py
+3
-4
general.py
utils/general.py
+5
-0
torch_utils.py
utils/torch_utils.py
+0
-5
没有找到文件。
hubconf.py
浏览文件 @
e189fa15
...
@@ -30,7 +30,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
...
@@ -30,7 +30,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
from
models.experimental
import
attempt_load
from
models.experimental
import
attempt_load
from
models.yolo
import
Model
from
models.yolo
import
Model
from
utils.downloads
import
attempt_download
from
utils.downloads
import
attempt_download
from
utils.general
import
check_requirements
,
set_logging
from
utils.general
import
check_requirements
,
intersect_dicts
,
set_logging
from
utils.torch_utils
import
select_device
from
utils.torch_utils
import
select_device
file
=
Path
(
__file__
)
.
resolve
()
file
=
Path
(
__file__
)
.
resolve
()
...
@@ -49,9 +49,8 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
...
@@ -49,9 +49,8 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
model
=
Model
(
cfg
,
channels
,
classes
)
# create model
model
=
Model
(
cfg
,
channels
,
classes
)
# create model
if
pretrained
:
if
pretrained
:
ckpt
=
torch
.
load
(
attempt_download
(
path
),
map_location
=
device
)
# load
ckpt
=
torch
.
load
(
attempt_download
(
path
),
map_location
=
device
)
# load
msd
=
model
.
state_dict
()
# model state_dict
csd
=
ckpt
[
'model'
]
.
float
()
.
state_dict
()
# checkpoint state_dict as FP32
csd
=
ckpt
[
'model'
]
.
float
()
.
state_dict
()
# checkpoint state_dict as FP32
csd
=
{
k
:
v
for
k
,
v
in
csd
.
items
()
if
msd
[
k
]
.
shape
==
v
.
shape
}
# filter
csd
=
intersect_dicts
(
csd
,
model
.
state_dict
(),
exclude
=
[
'anchors'
])
# intersect
model
.
load_state_dict
(
csd
,
strict
=
False
)
# load
model
.
load_state_dict
(
csd
,
strict
=
False
)
# load
if
len
(
ckpt
[
'model'
]
.
names
)
==
classes
:
if
len
(
ckpt
[
'model'
]
.
names
)
==
classes
:
model
.
names
=
ckpt
[
'model'
]
.
names
# set class names attribute
model
.
names
=
ckpt
[
'model'
]
.
names
# set class names attribute
...
...
train.py
浏览文件 @
e189fa15
...
@@ -43,15 +43,14 @@ from utils.datasets import create_dataloader
...
@@ -43,15 +43,14 @@ from utils.datasets import create_dataloader
from
utils.downloads
import
attempt_download
from
utils.downloads
import
attempt_download
from
utils.general
import
(
LOGGER
,
check_dataset
,
check_file
,
check_git_status
,
check_img_size
,
check_requirements
,
from
utils.general
import
(
LOGGER
,
check_dataset
,
check_file
,
check_git_status
,
check_img_size
,
check_requirements
,
check_suffix
,
check_yaml
,
colorstr
,
get_latest_run
,
increment_path
,
init_seeds
,
check_suffix
,
check_yaml
,
colorstr
,
get_latest_run
,
increment_path
,
init_seeds
,
labels_to_class_weights
,
labels_to_image_weights
,
methods
,
one_cycle
,
print_args
,
intersect_dicts
,
labels_to_class_weights
,
labels_to_image_weights
,
methods
,
one_cycle
,
print_mutation
,
strip_optimizer
)
print_
args
,
print_
mutation
,
strip_optimizer
)
from
utils.loggers
import
Loggers
from
utils.loggers
import
Loggers
from
utils.loggers.wandb.wandb_utils
import
check_wandb_resume
from
utils.loggers.wandb.wandb_utils
import
check_wandb_resume
from
utils.loss
import
ComputeLoss
from
utils.loss
import
ComputeLoss
from
utils.metrics
import
fitness
from
utils.metrics
import
fitness
from
utils.plots
import
plot_evolve
,
plot_labels
from
utils.plots
import
plot_evolve
,
plot_labels
from
utils.torch_utils
import
(
EarlyStopping
,
ModelEMA
,
de_parallel
,
intersect_dicts
,
select_device
,
from
utils.torch_utils
import
EarlyStopping
,
ModelEMA
,
de_parallel
,
select_device
,
torch_distributed_zero_first
torch_distributed_zero_first
)
LOCAL_RANK
=
int
(
os
.
getenv
(
'LOCAL_RANK'
,
-
1
))
# https://pytorch.org/docs/stable/elastic/run.html
LOCAL_RANK
=
int
(
os
.
getenv
(
'LOCAL_RANK'
,
-
1
))
# https://pytorch.org/docs/stable/elastic/run.html
RANK
=
int
(
os
.
getenv
(
'RANK'
,
-
1
))
RANK
=
int
(
os
.
getenv
(
'RANK'
,
-
1
))
...
...
utils/general.py
浏览文件 @
e189fa15
...
@@ -125,6 +125,11 @@ def init_seeds(seed=0):
...
@@ -125,6 +125,11 @@ def init_seeds(seed=0):
cudnn
.
benchmark
,
cudnn
.
deterministic
=
(
False
,
True
)
if
seed
==
0
else
(
True
,
False
)
cudnn
.
benchmark
,
cudnn
.
deterministic
=
(
False
,
True
)
if
seed
==
0
else
(
True
,
False
)
def
intersect_dicts
(
da
,
db
,
exclude
=
()):
# Dictionary intersection of matching keys and shapes, omitting 'exclude' keys, using da values
return
{
k
:
v
for
k
,
v
in
da
.
items
()
if
k
in
db
and
not
any
(
x
in
k
for
x
in
exclude
)
and
v
.
shape
==
db
[
k
]
.
shape
}
def
get_latest_run
(
search_dir
=
'.'
):
def
get_latest_run
(
search_dir
=
'.'
):
# Return path to most recent 'last.pt' in /runs (i.e. to --resume from)
# Return path to most recent 'last.pt' in /runs (i.e. to --resume from)
last_list
=
glob
.
glob
(
f
'{search_dir}/**/last*.pt'
,
recursive
=
True
)
last_list
=
glob
.
glob
(
f
'{search_dir}/**/last*.pt'
,
recursive
=
True
)
...
...
utils/torch_utils.py
浏览文件 @
e189fa15
...
@@ -153,11 +153,6 @@ def de_parallel(model):
...
@@ -153,11 +153,6 @@ def de_parallel(model):
return
model
.
module
if
is_parallel
(
model
)
else
model
return
model
.
module
if
is_parallel
(
model
)
else
model
def
intersect_dicts
(
da
,
db
,
exclude
=
()):
# Dictionary intersection of matching keys and shapes, omitting 'exclude' keys, using da values
return
{
k
:
v
for
k
,
v
in
da
.
items
()
if
k
in
db
and
not
any
(
x
in
k
for
x
in
exclude
)
and
v
.
shape
==
db
[
k
]
.
shape
}
def
initialize_weights
(
model
):
def
initialize_weights
(
model
):
for
m
in
model
.
modules
():
for
m
in
model
.
modules
():
t
=
type
(
m
)
t
=
type
(
m
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论