Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
5122a448
Commit
5122a448
authored
Oct 21, 2020
by
vishnubanna
Browse files
PR1 darknet
parent
bfbb32aa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
23 deletions
+19
-23
official/vision/beta/projects/yolo/modeling/backbones/Darknet.py
...l/vision/beta/projects/yolo/modeling/backbones/Darknet.py
+19
-23
No files found.
official/vision/beta/projects/yolo/modeling/backbones/Darknet.py
View file @
5122a448
...
@@ -5,9 +5,8 @@ import collections
...
@@ -5,9 +5,8 @@ import collections
from
official.vision.beta.modeling.backbones
import
factory
from
official.vision.beta.modeling.backbones
import
factory
from
official.vision.beta.projects.yolo.modeling
import
building_blocks
as
nn_blocks
from
official.vision.beta.projects.yolo.modeling
import
building_blocks
as
nn_blocks
# builder required classes
# builder required classes
class
CSP
BlockConfig
(
object
):
class
BlockConfig
(
object
):
def
__init__
(
self
,
layer
,
stack
,
reps
,
bottleneck
,
filters
,
kernel_size
,
def
__init__
(
self
,
layer
,
stack
,
reps
,
bottleneck
,
filters
,
kernel_size
,
strides
,
padding
,
activation
,
route
,
output_name
,
is_output
):
strides
,
padding
,
activation
,
route
,
output_name
,
is_output
):
'''
'''
...
@@ -35,27 +34,12 @@ class CSPBlockConfig(object):
...
@@ -35,27 +34,12 @@ class CSPBlockConfig(object):
self
.
is_output
=
is_output
self
.
is_output
=
is_output
return
return
def
csp_
build_block_specs
(
config
):
def
build_block_specs
(
config
):
specs
=
[]
specs
=
[]
for
layer
in
config
:
for
layer
in
config
:
specs
.
append
(
CSP
BlockConfig
(
*
layer
))
specs
.
append
(
BlockConfig
(
*
layer
))
return
specs
return
specs
class
layer_registry
(
object
):
def
__init__
(
self
):
self
.
_layer_dict
=
{
"DarkTiny"
:
(
nn_blocks
.
DarkTiny
,
darktiny_config_todict
),
"DarkConv"
:
(
nn_blocks
.
DarkConv
,
darkconv_config_todict
),
"MaxPool"
:
(
tf
.
keras
.
layers
.
MaxPool2D
,
maxpool_config_todict
)}
return
def
_get_layer
(
self
,
key
):
return
self
.
_layer_dict
[
key
]
def
__call__
(
self
,
config
,
kwargs
):
layer
,
get_param_dict
=
self
.
_get_layer
(
config
.
layer
)
param_dict
=
get_param_dict
(
config
,
kwargs
)
return
layer
(
**
param_dict
)
def
darkconv_config_todict
(
config
,
kwargs
):
def
darkconv_config_todict
(
config
,
kwargs
):
dictvals
=
{
dictvals
=
{
"filters"
:
config
.
filters
,
"filters"
:
config
.
filters
,
...
@@ -79,6 +63,21 @@ def maxpool_config_todict(config, kwargs):
...
@@ -79,6 +63,21 @@ def maxpool_config_todict(config, kwargs):
"padding"
:
config
.
padding
,
"padding"
:
config
.
padding
,
"name"
:
kwargs
[
"name"
]}
"name"
:
kwargs
[
"name"
]}
class
layer_registry
(
object
):
def
__init__
(
self
):
self
.
_layer_dict
=
{
"DarkTiny"
:
(
nn_blocks
.
DarkTiny
,
darktiny_config_todict
),
"DarkConv"
:
(
nn_blocks
.
DarkConv
,
darkconv_config_todict
),
"MaxPool"
:
(
tf
.
keras
.
layers
.
MaxPool2D
,
maxpool_config_todict
)}
return
def
_get_layer
(
self
,
key
):
return
self
.
_layer_dict
[
key
]
def
__call__
(
self
,
config
,
kwargs
):
layer
,
get_param_dict
=
self
.
_get_layer
(
config
.
layer
)
param_dict
=
get_param_dict
(
config
,
kwargs
)
return
layer
(
**
param_dict
)
# model configs
# model configs
LISTNAMES
=
[
"default_layer_name"
,
"level_type"
,
"number_of_layers_in_level"
,
"bottleneck"
,
"filters"
,
"kernal_size"
,
"strides"
,
"padding"
,
"default_activation"
,
"route"
,
"level/name"
,
"is_output"
]
LISTNAMES
=
[
"default_layer_name"
,
"level_type"
,
"number_of_layers_in_level"
,
"bottleneck"
,
"filters"
,
"kernal_size"
,
"strides"
,
"padding"
,
"default_activation"
,
"route"
,
"level/name"
,
"is_output"
]
CSPDARKNET53
=
{
CSPDARKNET53
=
{
...
@@ -307,14 +306,12 @@ class Darknet(ks.Model):
...
@@ -307,14 +306,12 @@ class Darknet(ks.Model):
self
.
_default_dict
[
"name"
]
=
None
self
.
_default_dict
[
"name"
]
=
None
return
x
return
x
@
staticmethod
@
staticmethod
def
get_model_config
(
name
):
def
get_model_config
(
name
):
name
=
name
.
lower
()
name
=
name
.
lower
()
backbone
=
BACKBONES
[
name
][
"backbone"
]
backbone
=
BACKBONES
[
name
][
"backbone"
]
splits
=
BACKBONES
[
name
][
"splits"
]
splits
=
BACKBONES
[
name
][
"splits"
]
return
csp_
build_block_specs
(
backbone
),
splits
return
build_block_specs
(
backbone
),
splits
@
factory
.
register_backbone_builder
(
'darknet'
)
@
factory
.
register_backbone_builder
(
'darknet'
)
def
build_darknet
(
def
build_darknet
(
...
@@ -325,7 +322,6 @@ def build_darknet(
...
@@ -325,7 +322,6 @@ def build_darknet(
backbone_type
=
model_config
.
backbone
.
type
backbone_type
=
model_config
.
backbone
.
type
backbone_cfg
=
model_config
.
backbone
.
get
()
backbone_cfg
=
model_config
.
backbone
.
get
()
norm_activation_config
=
model_config
.
norm_activation
norm_activation_config
=
model_config
.
norm_activation
return
Darknet
(
model_id
=
backbone_cfg
.
model_id
,
return
Darknet
(
model_id
=
backbone_cfg
.
model_id
,
input_shape
=
input_specs
,
input_shape
=
input_specs
,
activation
=
norm_activation_config
.
activation
,
activation
=
norm_activation_config
.
activation
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment