Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
曾经的那一瞬间
Models
提交
f27d88f9
M
Models
项目概览
曾经的那一瞬间
/
Models
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f27d88f9
编写于
9月 09, 2021
作者:
V
Vishnu Banna
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
backbone update
上级
8f33972c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
23 deletion
+23
-23
official/vision/beta/projects/yolo/modeling/backbones/darknet.py
...l/vision/beta/projects/yolo/modeling/backbones/darknet.py
+23
-23
未找到文件。
official/vision/beta/projects/yolo/modeling/backbones/darknet.py
浏览文件 @
f27d88f9
...
...
@@ -43,7 +43,6 @@ from official.modeling import hyperparams
from
official.vision.beta.modeling.backbones
import
factory
from
official.vision.beta.projects.yolo.modeling.layers
import
nn_blocks
class
BlockConfig
:
"""Class to store layer config to make code more readable."""
...
...
@@ -103,11 +102,11 @@ class LayerBuilder:
def
__init__
(
self
):
self
.
_layer_dict
=
{
'ConvBN'
:
(
nn_blocks
.
ConvBN
,
self
.
ConvBN
_config_todict
),
'ConvBN'
:
(
nn_blocks
.
ConvBN
,
self
.
conv_bn
_config_todict
),
'MaxPool'
:
(
tf
.
keras
.
layers
.
MaxPool2D
,
self
.
maxpool_config_todict
)
}
def
ConvBN
_config_todict
(
self
,
config
,
kwargs
):
def
conv_bn
_config_todict
(
self
,
config
,
kwargs
):
dictvals
=
{
'filters'
:
config
.
filters
,
'kernel_size'
:
config
.
kernel_size
,
...
...
@@ -140,7 +139,7 @@ class LayerBuilder:
LISTNAMES
=
[
'default_layer_name'
,
'level_type'
,
'number_of_layers_in_level'
,
'bottleneck'
,
'filters'
,
'kernal_size'
,
'pool_size'
,
'strides'
,
'padding'
,
'default_activation'
,
'route'
,
'di
a
lation'
,
'level/name'
,
'is_output'
'default_activation'
,
'route'
,
'dilation'
,
'level/name'
,
'is_output'
]
CSPDARKNET53
=
{
...
...
@@ -384,7 +383,7 @@ class Darknet(tf.keras.Model):
max_level
=
5
,
width_scale
=
1.0
,
depth_scale
=
1.0
,
csp_level_mod
=
[]
,
csp_level_mod
=
()
,
activation
=
None
,
use_sync_bn
=
False
,
norm_momentum
=
0.99
,
...
...
@@ -461,23 +460,23 @@ class Darknet(tf.keras.Model):
if
config
.
stack
is
None
:
x
=
self
.
_build_block
(
stack_outputs
[
config
.
route
],
config
,
name
=
f
"
{
config
.
layer
}
_
{
i
}
"
)
stack_outputs
[
config
.
route
],
config
,
name
=
f
'
{
config
.
layer
}
_
{
i
}
'
)
stack_outputs
.
append
(
x
)
elif
config
.
stack
==
'residual'
:
x
=
self
.
_residual_stack
(
stack_outputs
[
config
.
route
],
config
,
name
=
f
"
{
config
.
layer
}
_
{
i
}
"
)
stack_outputs
[
config
.
route
],
config
,
name
=
f
'
{
config
.
layer
}
_
{
i
}
'
)
stack_outputs
.
append
(
x
)
elif
config
.
stack
==
'csp'
:
x
=
self
.
_csp_stack
(
stack_outputs
[
config
.
route
],
config
,
name
=
f
"
{
config
.
layer
}
_
{
i
}
"
)
stack_outputs
[
config
.
route
],
config
,
name
=
f
'
{
config
.
layer
}
_
{
i
}
'
)
stack_outputs
.
append
(
x
)
elif
config
.
stack
==
'csp_tiny'
:
x_pass
,
x
=
self
.
_csp_tiny_stack
(
stack_outputs
[
config
.
route
],
config
,
name
=
f
"
{
config
.
layer
}
_
{
i
}
"
)
stack_outputs
[
config
.
route
],
config
,
name
=
f
'
{
config
.
layer
}
_
{
i
}
'
)
stack_outputs
.
append
(
x_pass
)
elif
config
.
stack
==
'tiny'
:
x
=
self
.
_tiny_stack
(
stack_outputs
[
config
.
route
],
config
,
name
=
f
"
{
config
.
layer
}
_
{
i
}
"
)
stack_outputs
[
config
.
route
],
config
,
name
=
f
'
{
config
.
layer
}
_
{
i
}
'
)
stack_outputs
.
append
(
x
)
if
(
config
.
is_output
and
self
.
_min_size
is
None
):
endpoints
[
str
(
config
.
output_name
)]
=
x
...
...
@@ -504,7 +503,7 @@ class Darknet(tf.keras.Model):
residual_filter_scale
=
1
scale_filters
=
2
self
.
_default_dict
[
'activation'
]
=
self
.
_get_activation
(
config
.
activation
)
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_csp_down"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_csp_down'
if
self
.
_dilate
:
self
.
_default_dict
[
'dilation_rate'
]
=
config
.
dilation_rate
degrid
=
int
(
tf
.
math
.
log
(
float
(
config
.
dilation_rate
))
/
tf
.
math
.
log
(
2.
))
...
...
@@ -522,7 +521,7 @@ class Darknet(tf.keras.Model):
dilated_reps
=
config
.
repetitions
-
degrid
for
i
in
range
(
dilated_reps
):
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_
{
i
}
"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_
{
i
}
'
x
=
nn_blocks
.
DarkResidual
(
filters
=
config
.
filters
//
scale_filters
,
filter_scale
=
residual_filter_scale
,
...
...
@@ -533,14 +532,14 @@ class Darknet(tf.keras.Model):
self
.
_default_dict
[
'dilation_rate'
]
=
max
(
1
,
self
.
_default_dict
[
'dilation_rate'
]
//
2
)
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_
{
i
}
_degrided_
{
self
.
_default_dict
[
'dilation_rate'
]
}
"
'name'
]
=
f
"
{
name
}
_
{
i
}
_degrid
d
ed_
{
self
.
_default_dict
[
'dilation_rate'
]
}
"
x
=
nn_blocks
.
DarkResidual
(
filters
=
config
.
filters
//
scale_filters
,
filter_scale
=
residual_filter_scale
,
**
self
.
_default_dict
)(
x
)
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_csp_connect"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_csp_connect'
output
=
nn_blocks
.
CSPConnect
(
filters
=
config
.
filters
,
filter_scale
=
csp_filter_scale
,
...
...
@@ -551,7 +550,7 @@ class Darknet(tf.keras.Model):
def
_csp_tiny_stack
(
self
,
inputs
,
config
,
name
):
self
.
_default_dict
[
'activation'
]
=
self
.
_get_activation
(
config
.
activation
)
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_csp_tiny"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_csp_tiny'
x
,
x_route
=
nn_blocks
.
CSPTiny
(
filters
=
config
.
filters
,
**
self
.
_default_dict
)(
inputs
)
...
...
@@ -565,10 +564,10 @@ class Darknet(tf.keras.Model):
strides
=
config
.
strides
,
padding
=
'same'
,
data_format
=
None
,
name
=
f
"
{
name
}
_tiny/pool"
)(
name
=
f
'
{
name
}
_tiny/pool'
)(
inputs
)
self
.
_default_dict
[
'activation'
]
=
self
.
_get_activation
(
config
.
activation
)
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_tiny/conv"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_tiny/conv'
x
=
nn_blocks
.
ConvBN
(
filters
=
config
.
filters
,
kernel_size
=
(
3
,
3
),
...
...
@@ -582,7 +581,7 @@ class Darknet(tf.keras.Model):
def
_residual_stack
(
self
,
inputs
,
config
,
name
):
self
.
_default_dict
[
'activation'
]
=
self
.
_get_activation
(
config
.
activation
)
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_residual_down"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_residual_down'
if
self
.
_dilate
:
self
.
_default_dict
[
'dilation_rate'
]
=
config
.
dilation_rate
if
config
.
repetitions
<
8
:
...
...
@@ -597,7 +596,7 @@ class Darknet(tf.keras.Model):
dilated_reps
=
config
.
repetitions
-
self
.
_default_dict
[
'dilation_rate'
]
//
2
-
1
for
i
in
range
(
dilated_reps
):
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_
{
i
}
"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_
{
i
}
'
x
=
nn_blocks
.
DarkResidual
(
filters
=
config
.
filters
,
**
self
.
_default_dict
)(
x
)
...
...
@@ -606,7 +605,7 @@ class Darknet(tf.keras.Model):
self
.
_default_dict
[
'dilation_rate'
]
=
self
.
_default_dict
[
'dilation_rate'
]
//
2
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_
{
i
}
_degrided_
{
self
.
_default_dict
[
'dilation_rate'
]
}
"
'name'
]
=
f
"
{
name
}
_
{
i
}
_degrid
d
ed_
{
self
.
_default_dict
[
'dilation_rate'
]
}
"
x
=
nn_blocks
.
DarkResidual
(
filters
=
config
.
filters
,
**
self
.
_default_dict
)(
x
)
...
...
@@ -621,7 +620,7 @@ class Darknet(tf.keras.Model):
i
=
0
self
.
_default_dict
[
'activation'
]
=
self
.
_get_activation
(
config
.
activation
)
while
i
<
config
.
repetitions
:
self
.
_default_dict
[
'name'
]
=
f
"
{
name
}
_
{
i
}
"
self
.
_default_dict
[
'name'
]
=
f
'
{
name
}
_
{
i
}
'
layer
=
self
.
_registry
(
config
,
self
.
_default_dict
)
x
=
layer
(
x
)
i
+=
1
...
...
@@ -663,12 +662,13 @@ class Darknet(tf.keras.Model):
@
factory
.
register_backbone_builder
(
'darknet'
)
def
build_darknet
(
input_specs
:
tf
.
keras
.
layers
.
InputSpec
,
backbone_c
onfi
g
:
hyperparams
.
Config
,
backbone_c
f
g
:
hyperparams
.
Config
,
norm_activation_config
:
hyperparams
.
Config
,
l2_regularizer
:
tf
.
keras
.
regularizers
.
Regularizer
=
None
)
->
tf
.
keras
.
Model
:
"""Builds darknet."""
backbone_cfg
=
backbone_config
.
get
()
backbone_cfg
=
backbone_cfg
.
get
()
model
=
Darknet
(
model_id
=
backbone_cfg
.
model_id
,
min_level
=
backbone_cfg
.
min_level
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录