Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MLAir
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esde
machine-learning
MLAir
Commits
63aed15e
Commit
63aed15e
authored
3 years ago
by
leufen1
Browse files
Options
Downloads
Patches
Plain Diff
add filter/pool size to layer name
parent
64325ec8
No related branches found
No related tags found
5 merge requests
!430
update recent developments
,
!413
update release branch
,
!412
Resolve "release v2.0.0"
,
!407
Lukas issue368 feat prepare cnn class for filter benchmarking
,
!403
Resolve "prepare CNN class for filter benchmarking"
Pipeline
#94802
passed
3 years ago
Stage: test
Stage: docs
Stage: pages
Stage: deploy
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlair/model_modules/branched_input_networks.py
+21
-4
21 additions, 4 deletions
mlair/model_modules/branched_input_networks.py
mlair/model_modules/convolutional_networks.py
+16
-3
16 additions, 3 deletions
mlair/model_modules/convolutional_networks.py
with
37 additions
and
7 deletions
mlair/model_modules/branched_input_networks.py
+
21
−
4
View file @
63aed15e
from
functools
import
partial
,
reduce
from
functools
import
partial
,
reduce
import
copy
import
copy
from
typing
import
Union
from
tensorflow
import
keras
as
keras
from
tensorflow
import
keras
as
keras
...
@@ -40,10 +41,12 @@ class BranchedInputCNN(CNNfromConfig): # pragma: no cover
...
@@ -40,10 +41,12 @@ class BranchedInputCNN(CNNfromConfig): # pragma: no cover
assert
pos
==
stop_pos
assert
pos
==
stop_pos
break
break
layer
,
layer_kwargs
,
follow_up_layer
=
self
.
_extract_layer_conf
(
layer_opts
)
layer
,
layer_kwargs
,
follow_up_layer
=
self
.
_extract_layer_conf
(
layer_opts
)
x_in_b
=
layer
(
**
layer_kwargs
,
name
=
f
"
{
layer
.
__name__
}
_branch
{
branch
+
1
}
_
{
pos
+
1
}
"
)(
x_in_b
)
layer_name
=
self
.
_get_layer_name
(
layer
,
layer_kwargs
,
pos
,
branch
)
x_in_b
=
layer
(
**
layer_kwargs
,
name
=
layer_name
)(
x_in_b
)
if
follow_up_layer
is
not
None
:
if
follow_up_layer
is
not
None
:
for
follow_up
in
to_list
(
follow_up_layer
):
for
follow_up
in
to_list
(
follow_up_layer
):
x_in_b
=
follow_up
(
name
=
f
"
{
follow_up
.
__name__
}
_branch
{
branch
+
1
}
_
{
pos
+
1
}
"
)(
x_in_b
)
layer_name
=
self
.
_get_layer_name
(
follow_up
,
None
,
pos
,
branch
)
x_in_b
=
follow_up
(
name
=
layer_name
)(
x_in_b
)
self
.
_layer_save
.
append
({
"
layer
"
:
layer
,
**
layer_kwargs
,
"
follow_up_layer
"
:
follow_up_layer
,
self
.
_layer_save
.
append
({
"
layer
"
:
layer
,
**
layer_kwargs
,
"
follow_up_layer
"
:
follow_up_layer
,
"
branch
"
:
branch
})
"
branch
"
:
branch
})
x_in
.
append
(
x_in_b
)
x_in
.
append
(
x_in_b
)
...
@@ -55,10 +58,12 @@ class BranchedInputCNN(CNNfromConfig): # pragma: no cover
...
@@ -55,10 +58,12 @@ class BranchedInputCNN(CNNfromConfig): # pragma: no cover
for
pos
,
layer_opts
in
enumerate
(
self
.
conf
[
stop_pos
+
1
:]):
for
pos
,
layer_opts
in
enumerate
(
self
.
conf
[
stop_pos
+
1
:]):
print
(
layer_opts
)
print
(
layer_opts
)
layer
,
layer_kwargs
,
follow_up_layer
=
self
.
_extract_layer_conf
(
layer_opts
)
layer
,
layer_kwargs
,
follow_up_layer
=
self
.
_extract_layer_conf
(
layer_opts
)
x_concat
=
layer
(
**
layer_kwargs
,
name
=
f
"
{
layer
.
__name__
}
_
{
pos
+
stop_pos
+
1
}
"
)(
x_concat
)
layer_name
=
self
.
_get_layer_name
(
layer
,
layer_kwargs
,
pos
+
stop_pos
,
None
)
x_concat
=
layer
(
**
layer_kwargs
,
name
=
layer_name
)(
x_concat
)
if
follow_up_layer
is
not
None
:
if
follow_up_layer
is
not
None
:
for
follow_up
in
to_list
(
follow_up_layer
):
for
follow_up
in
to_list
(
follow_up_layer
):
x_concat
=
follow_up
(
name
=
f
"
{
follow_up
.
__name__
}
_
{
pos
+
stop_pos
+
1
}
"
)(
x_concat
)
layer_name
=
self
.
_get_layer_name
(
follow_up
,
None
,
pos
+
stop_pos
,
None
)
x_concat
=
follow_up
(
name
=
layer_name
)(
x_concat
)
self
.
_layer_save
.
append
({
"
layer
"
:
layer
,
**
layer_kwargs
,
"
follow_up_layer
"
:
follow_up_layer
,
self
.
_layer_save
.
append
({
"
layer
"
:
layer
,
**
layer_kwargs
,
"
follow_up_layer
"
:
follow_up_layer
,
"
branch
"
:
"
concat
"
})
"
branch
"
:
"
concat
"
})
...
@@ -67,6 +72,18 @@ class BranchedInputCNN(CNNfromConfig): # pragma: no cover
...
@@ -67,6 +72,18 @@ class BranchedInputCNN(CNNfromConfig): # pragma: no cover
self
.
model
=
keras
.
Model
(
inputs
=
x_input
,
outputs
=
[
out
])
self
.
model
=
keras
.
Model
(
inputs
=
x_input
,
outputs
=
[
out
])
print
(
self
.
model
.
summary
())
print
(
self
.
model
.
summary
())
@staticmethod
def
_get_layer_name
(
layer
:
keras
.
layers
,
layer_kwargs
:
Union
[
dict
,
None
],
pos
:
int
,
branch
:
int
=
None
):
name
=
layer
.
__name__
if
"
Conv
"
in
layer
.
__name__
and
isinstance
(
layer_kwargs
,
dict
)
and
"
kernel_size
"
in
layer_kwargs
:
name
=
name
+
"
_
"
+
"
x
"
.
join
(
map
(
str
,
layer_kwargs
[
"
kernel_size
"
]))
if
"
Pooling
"
in
layer
.
__name__
and
isinstance
(
layer_kwargs
,
dict
)
and
"
pool_size
"
in
layer_kwargs
:
name
=
name
+
"
_
"
+
"
x
"
.
join
(
map
(
str
,
layer_kwargs
[
"
pool_size
"
]))
if
branch
is
not
None
:
name
+=
f
"
_branch
{
branch
+
1
}
"
name
+=
f
"
_
{
pos
+
1
}
"
return
name
class
BranchedInputRNN
(
RNN
):
# pragma: no cover
class
BranchedInputRNN
(
RNN
):
# pragma: no cover
"""
A recurrent neural network with multiple input branches.
"""
"""
A recurrent neural network with multiple input branches.
"""
...
...
This diff is collapsed.
Click to expand it.
mlair/model_modules/convolutional_networks.py
+
16
−
3
View file @
63aed15e
...
@@ -2,6 +2,7 @@ __author__ = "Lukas Leufen"
...
@@ -2,6 +2,7 @@ __author__ = "Lukas Leufen"
__date__
=
'
2021-02-
'
__date__
=
'
2021-02-
'
from
functools
import
reduce
,
partial
from
functools
import
reduce
,
partial
from
typing
import
Union
from
mlair.model_modules
import
AbstractModelClass
from
mlair.model_modules
import
AbstractModelClass
from
mlair.helpers
import
select_from_dict
,
to_list
from
mlair.helpers
import
select_from_dict
,
to_list
...
@@ -80,13 +81,15 @@ class CNNfromConfig(AbstractModelClass):
...
@@ -80,13 +81,15 @@ class CNNfromConfig(AbstractModelClass):
x_input
=
keras
.
layers
.
Input
(
shape
=
self
.
_input_shape
)
x_input
=
keras
.
layers
.
Input
(
shape
=
self
.
_input_shape
)
x_in
=
x_input
x_in
=
x_input
for
layer_opts
in
self
.
conf
:
for
pos
,
layer_opts
in
enumerate
(
self
.
conf
)
:
print
(
layer_opts
)
print
(
layer_opts
)
layer
,
layer_kwargs
,
follow_up_layer
=
self
.
_extract_layer_conf
(
layer_opts
)
layer
,
layer_kwargs
,
follow_up_layer
=
self
.
_extract_layer_conf
(
layer_opts
)
x_in
=
layer
(
**
layer_kwargs
)(
x_in
)
layer_name
=
self
.
_get_layer_name
(
layer
,
layer_kwargs
,
pos
)
x_in
=
layer
(
**
layer_kwargs
,
name
=
layer_name
)(
x_in
)
if
follow_up_layer
is
not
None
:
if
follow_up_layer
is
not
None
:
for
follow_up
in
to_list
(
follow_up_layer
):
for
follow_up
in
to_list
(
follow_up_layer
):
x_in
=
follow_up
()(
x_in
)
layer_name
=
self
.
_get_layer_name
(
follow_up
,
None
,
pos
)
x_in
=
follow_up
(
name
=
layer_name
)(
x_in
)
self
.
_layer_save
.
append
({
"
layer
"
:
layer
,
**
layer_kwargs
,
"
follow_up_layer
"
:
follow_up_layer
})
self
.
_layer_save
.
append
({
"
layer
"
:
layer
,
**
layer_kwargs
,
"
follow_up_layer
"
:
follow_up_layer
})
x_in
=
keras
.
layers
.
Dense
(
self
.
_output_shape
)(
x_in
)
x_in
=
keras
.
layers
.
Dense
(
self
.
_output_shape
)(
x_in
)
...
@@ -94,6 +97,16 @@ class CNNfromConfig(AbstractModelClass):
...
@@ -94,6 +97,16 @@ class CNNfromConfig(AbstractModelClass):
self
.
model
=
keras
.
Model
(
inputs
=
x_input
,
outputs
=
[
out
])
self
.
model
=
keras
.
Model
(
inputs
=
x_input
,
outputs
=
[
out
])
print
(
self
.
model
.
summary
())
print
(
self
.
model
.
summary
())
@staticmethod
def
_get_layer_name
(
layer
:
keras
.
layers
,
layer_kwargs
:
Union
[
dict
,
None
],
pos
:
int
,
*
args
):
name
=
layer
.
__name__
if
"
Conv
"
in
layer
.
__name__
and
isinstance
(
layer_kwargs
,
dict
)
and
"
kernel_size
"
in
layer_kwargs
:
name
=
name
+
"
_
"
+
"
x
"
.
join
(
map
(
str
,
layer_kwargs
[
"
kernel_size
"
]))
if
"
Pooling
"
in
layer
.
__name__
and
isinstance
(
layer_kwargs
,
dict
)
and
"
pool_size
"
in
layer_kwargs
:
name
=
name
+
"
_
"
+
"
x
"
.
join
(
map
(
str
,
layer_kwargs
[
"
pool_size
"
]))
name
+=
f
"
_
{
pos
+
1
}
"
return
name
def
_set_optimizer
(
self
,
optimizer
,
**
kwargs
):
def
_set_optimizer
(
self
,
optimizer
,
**
kwargs
):
try
:
try
:
opt_name
=
optimizer
.
lower
()
opt_name
=
optimizer
.
lower
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment