Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yolov5
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Administrator
yolov5
Commits
02445d17
提交
02445d17
authored
7月 13, 2020
作者:
Glenn Jocher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improved model.yaml source tracking
上级
c80b249e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
14 行删除
+20
-14
detect.py
detect.py
+1
-1
yolo.py
models/yolo.py
+19
-13
没有找到文件。
detect.py
浏览文件 @
02445d17
...
@@ -128,7 +128,7 @@ def detect(save_img=False):
...
@@ -128,7 +128,7 @@ def detect(save_img=False):
if
save_txt
or
save_img
:
if
save_txt
or
save_img
:
print
(
'Results saved to
%
s'
%
os
.
getcwd
()
+
os
.
sep
+
out
)
print
(
'Results saved to
%
s'
%
os
.
getcwd
()
+
os
.
sep
+
out
)
if
platform
==
'darwin'
:
# MacOS
if
platform
==
'darwin'
and
not
opt
.
update
:
# MacOS
os
.
system
(
'open '
+
save_path
)
os
.
system
(
'open '
+
save_path
)
print
(
'Done. (
%.3
fs)'
%
(
time
.
time
()
-
t0
))
print
(
'Done. (
%.3
fs)'
%
(
time
.
time
()
-
t0
))
...
...
models/yolo.py
浏览文件 @
02445d17
import
argparse
import
argparse
from
copy
import
deepcopy
from
models.experimental
import
*
from
models.experimental
import
*
...
@@ -43,20 +44,21 @@ class Detect(nn.Module):
...
@@ -43,20 +44,21 @@ class Detect(nn.Module):
class
Model
(
nn
.
Module
):
class
Model
(
nn
.
Module
):
def
__init__
(
self
,
model_
cfg
=
'yolov5s.yaml'
,
ch
=
3
,
nc
=
None
):
# model, input channels, number of classes
def
__init__
(
self
,
cfg
=
'yolov5s.yaml'
,
ch
=
3
,
nc
=
None
):
# model, input channels, number of classes
super
(
Model
,
self
)
.
__init__
()
super
(
Model
,
self
)
.
__init__
()
if
type
(
model_cfg
)
is
dict
:
if
isinstance
(
cfg
,
dict
)
:
self
.
md
=
model_
cfg
# model dict
self
.
yaml
=
cfg
# model dict
else
:
# is *.yaml
else
:
# is *.yaml
import
yaml
# for torch hub
import
yaml
# for torch hub
with
open
(
model_cfg
)
as
f
:
self
.
yaml_file
=
Path
(
cfg
)
.
name
self
.
md
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
# model dict
with
open
(
cfg
)
as
f
:
self
.
yaml
=
yaml
.
load
(
f
,
Loader
=
yaml
.
FullLoader
)
# model dict
# Define model
# Define model
if
nc
and
nc
!=
self
.
md
[
'nc'
]:
if
nc
and
nc
!=
self
.
yaml
[
'nc'
]:
print
(
'Overriding
%
s nc=
%
g with nc=
%
g'
%
(
model_cfg
,
self
.
md
[
'nc'
],
nc
))
print
(
'Overriding
%
s nc=
%
g with nc=
%
g'
%
(
cfg
,
self
.
yaml
[
'nc'
],
nc
))
self
.
md
[
'nc'
]
=
nc
# override yaml value
self
.
yaml
[
'nc'
]
=
nc
# override yaml value
self
.
model
,
self
.
save
=
parse_model
(
self
.
md
,
ch
=
[
ch
])
# model, savelist, ch_out
self
.
model
,
self
.
save
=
parse_model
(
deepcopy
(
self
.
yaml
)
,
ch
=
[
ch
])
# model, savelist, ch_out
# print([x.shape for x in self.forward(torch.zeros(1, ch, 64, 64))])
# print([x.shape for x in self.forward(torch.zeros(1, ch, 64, 64))])
# Build strides, anchors
# Build strides, anchors
...
@@ -148,17 +150,21 @@ class Model(nn.Module):
...
@@ -148,17 +150,21 @@ class Model(nn.Module):
m
.
conv
=
torch_utils
.
fuse_conv_and_bn
(
m
.
conv
,
m
.
bn
)
# update conv
m
.
conv
=
torch_utils
.
fuse_conv_and_bn
(
m
.
conv
,
m
.
bn
)
# update conv
m
.
bn
=
None
# remove batchnorm
m
.
bn
=
None
# remove batchnorm
m
.
forward
=
m
.
fuseforward
# update forward
m
.
forward
=
m
.
fuseforward
# update forward
torch_utils
.
model_info
(
self
)
self
.
info
(
)
return
self
return
self
def
parse_model
(
md
,
ch
):
# model_dict, input_channels(3)
def
info
(
self
):
# print model information
torch_utils
.
model_info
(
self
)
def
parse_model
(
d
,
ch
):
# model_dict, input_channels(3)
print
(
'
\n
%3
s
%18
s
%3
s
%10
s
%-40
s
%-30
s'
%
(
''
,
'from'
,
'n'
,
'params'
,
'module'
,
'arguments'
))
print
(
'
\n
%3
s
%18
s
%3
s
%10
s
%-40
s
%-30
s'
%
(
''
,
'from'
,
'n'
,
'params'
,
'module'
,
'arguments'
))
anchors
,
nc
,
gd
,
gw
=
md
[
'anchors'
],
md
[
'nc'
],
md
[
'depth_multiple'
],
m
d
[
'width_multiple'
]
anchors
,
nc
,
gd
,
gw
=
d
[
'anchors'
],
d
[
'nc'
],
d
[
'depth_multiple'
],
d
[
'width_multiple'
]
na
=
(
len
(
anchors
[
0
])
//
2
)
# number of anchors
na
=
(
len
(
anchors
[
0
])
//
2
)
# number of anchors
no
=
na
*
(
nc
+
5
)
# number of outputs = anchors * (classes + 5)
no
=
na
*
(
nc
+
5
)
# number of outputs = anchors * (classes + 5)
layers
,
save
,
c2
=
[],
[],
ch
[
-
1
]
# layers, savelist, ch out
layers
,
save
,
c2
=
[],
[],
ch
[
-
1
]
# layers, savelist, ch out
for
i
,
(
f
,
n
,
m
,
args
)
in
enumerate
(
md
[
'backbone'
]
+
m
d
[
'head'
]):
# from, number, module, args
for
i
,
(
f
,
n
,
m
,
args
)
in
enumerate
(
d
[
'backbone'
]
+
d
[
'head'
]):
# from, number, module, args
m
=
eval
(
m
)
if
isinstance
(
m
,
str
)
else
m
# eval strings
m
=
eval
(
m
)
if
isinstance
(
m
,
str
)
else
m
# eval strings
for
j
,
a
in
enumerate
(
args
):
for
j
,
a
in
enumerate
(
args
):
try
:
try
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论