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
abef8764
Commit
abef8764
authored
5 years ago
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
update paddings and helper functions (
#56
)
parent
f2ccaa3d
No related branches found
No related tags found
2 merge requests
!59
Develop
,
!46
Felix #56 advanced paddings
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/model_modules/advanced_paddings.py
+13
-10
13 additions, 10 deletions
src/model_modules/advanced_paddings.py
with
13 additions
and
10 deletions
src/model_modules/advanced_paddings.py
+
13
−
10
View file @
abef8764
...
@@ -12,7 +12,7 @@ from keras.utils.generic_utils import transpose_shape
...
@@ -12,7 +12,7 @@ from keras.utils.generic_utils import transpose_shape
from
keras.backend.common
import
normalize_data_format
from
keras.backend.common
import
normalize_data_format
class
p
ad
_u
tils
:
class
P
ad
U
tils
:
"""
"""
Helper class for advanced paddings
Helper class for advanced paddings
"""
"""
...
@@ -76,8 +76,12 @@ class pad_utils:
...
@@ -76,8 +76,12 @@ class pad_utils:
'
Found:
'
+
str
(
padding
))
'
Found:
'
+
str
(
padding
))
height_padding
=
conv_utils
.
normalize_tuple
(
padding
[
0
],
2
,
height_padding
=
conv_utils
.
normalize_tuple
(
padding
[
0
],
2
,
'
1st entry of padding
'
)
'
1st entry of padding
'
)
if
not
all
(
k
>=
0
for
k
in
height_padding
):
raise
ValueError
(
f
"
The `1st entry of padding` argument must be >= 0. Received:
{
padding
[
0
]
}
of type
{
type
(
padding
[
0
])
}
"
)
width_padding
=
conv_utils
.
normalize_tuple
(
padding
[
1
],
2
,
width_padding
=
conv_utils
.
normalize_tuple
(
padding
[
1
],
2
,
'
2nd entry of padding
'
)
'
2nd entry of padding
'
)
if
not
all
(
k
>=
0
for
k
in
width_padding
):
raise
ValueError
(
f
"
The `2nd entry of padding` argument must be >= 0. Received:
{
padding
[
1
]
}
of type
{
type
(
padding
[
1
])
}
"
)
normalized_padding
=
(
height_padding
,
width_padding
)
normalized_padding
=
(
height_padding
,
width_padding
)
else
:
else
:
raise
ValueError
(
'
`padding` should be either an int,
'
raise
ValueError
(
'
`padding` should be either an int,
'
...
@@ -85,7 +89,7 @@ class pad_utils:
...
@@ -85,7 +89,7 @@ class pad_utils:
'
(symmetric_height_pad, symmetric_width_pad),
'
'
(symmetric_height_pad, symmetric_width_pad),
'
'
or a tuple of 2 tuples of 2 ints
'
'
or a tuple of 2 tuples of 2 ints
'
'
((top_pad, bottom_pad), (left_pad, right_pad)).
'
'
((top_pad, bottom_pad), (left_pad, right_pad)).
'
'
Found:
'
+
str
(
padding
))
f
'
Found:
{
padding
}
of type
{
type
(
padding
)
}
'
)
return
normalized_padding
return
normalized_padding
...
@@ -151,13 +155,13 @@ class ReflectionPadding2D(_ZeroPadding):
...
@@ -151,13 +155,13 @@ class ReflectionPadding2D(_ZeroPadding):
padding
=
(
1
,
1
),
padding
=
(
1
,
1
),
data_format
=
None
,
data_format
=
None
,
**
kwargs
):
**
kwargs
):
normalized_padding
=
p
ad
_u
tils
.
check_padding_format
(
padding
=
padding
)
normalized_padding
=
P
ad
U
tils
.
check_padding_format
(
padding
=
padding
)
super
(
ReflectionPadding2D
,
self
).
__init__
(
normalized_padding
,
super
(
ReflectionPadding2D
,
self
).
__init__
(
normalized_padding
,
data_format
,
data_format
,
**
kwargs
)
**
kwargs
)
def
call
(
self
,
inputs
,
mask
=
None
):
def
call
(
self
,
inputs
,
mask
=
None
):
pattern
=
p
ad
_u
tils
.
spatial_2d_padding
(
padding
=
self
.
padding
,
data_format
=
self
.
data_format
)
pattern
=
P
ad
U
tils
.
spatial_2d_padding
(
padding
=
self
.
padding
,
data_format
=
self
.
data_format
)
return
tf
.
pad
(
inputs
,
pattern
,
'
REFLECT
'
)
return
tf
.
pad
(
inputs
,
pattern
,
'
REFLECT
'
)
...
@@ -222,13 +226,13 @@ class SymmetricPadding2D(_ZeroPadding):
...
@@ -222,13 +226,13 @@ class SymmetricPadding2D(_ZeroPadding):
padding
=
(
1
,
1
),
padding
=
(
1
,
1
),
data_format
=
None
,
data_format
=
None
,
**
kwargs
):
**
kwargs
):
normalized_padding
=
p
ad
_u
tils
.
check_padding_format
(
padding
=
padding
)
normalized_padding
=
P
ad
U
tils
.
check_padding_format
(
padding
=
padding
)
super
(
SymmetricPadding2D
,
self
).
__init__
(
normalized_padding
,
super
(
SymmetricPadding2D
,
self
).
__init__
(
normalized_padding
,
data_format
,
data_format
,
**
kwargs
)
**
kwargs
)
def
call
(
self
,
inputs
,
mask
=
None
):
def
call
(
self
,
inputs
,
mask
=
None
):
pattern
=
p
ad
_u
tils
.
spatial_2d_padding
(
padding
=
self
.
padding
,
data_format
=
self
.
data_format
)
pattern
=
P
ad
U
tils
.
spatial_2d_padding
(
padding
=
self
.
padding
,
data_format
=
self
.
data_format
)
return
tf
.
pad
(
inputs
,
pattern
,
'
SYMMETRIC
'
)
return
tf
.
pad
(
inputs
,
pattern
,
'
SYMMETRIC
'
)
...
@@ -241,11 +245,11 @@ if __name__ == '__main__':
...
@@ -241,11 +245,11 @@ if __name__ == '__main__':
y
=
x
.
mean
(
axis
=
(
1
,
2
))
y
=
x
.
mean
(
axis
=
(
1
,
2
))
x_input
=
Input
(
shape
=
x
.
shape
[
1
:])
x_input
=
Input
(
shape
=
x
.
shape
[
1
:])
pad1
=
p
ad
_u
tils
.
get_padding_for_same
(
kernel_1
)
pad1
=
P
ad
U
tils
.
get_padding_for_same
(
kernel_1
)
x_out
=
ReflectionPadding2D
(
padding
=
pad1
,
name
=
"
RefPAD
"
)(
x_input
)
x_out
=
ReflectionPadding2D
(
padding
=
pad1
,
name
=
"
RefPAD
"
)(
x_input
)
x_out
=
Conv2D
(
1
,
kernel_size
=
kernel_1
,
activation
=
'
relu
'
)(
x_out
)
x_out
=
Conv2D
(
5
,
kernel_size
=
kernel_1
,
activation
=
'
relu
'
)(
x_out
)
pad2
=
p
ad
_u
tils
.
get_padding_for_same
(
kernel_2
)
pad2
=
P
ad
U
tils
.
get_padding_for_same
(
kernel_2
)
x_out
=
SymmetricPadding2D
(
padding
=
pad2
,
name
=
"
SymPAD
"
)(
x_out
)
x_out
=
SymmetricPadding2D
(
padding
=
pad2
,
name
=
"
SymPAD
"
)(
x_out
)
x_out
=
Conv2D
(
2
,
kernel_size
=
kernel_2
,
activation
=
'
relu
'
)(
x_out
)
x_out
=
Conv2D
(
2
,
kernel_size
=
kernel_2
,
activation
=
'
relu
'
)(
x_out
)
x_out
=
Flatten
()(
x_out
)
x_out
=
Flatten
()(
x_out
)
...
@@ -254,6 +258,5 @@ if __name__ == '__main__':
...
@@ -254,6 +258,5 @@ if __name__ == '__main__':
model
=
Model
(
inputs
=
x_input
,
outputs
=
x_out
)
model
=
Model
(
inputs
=
x_input
,
outputs
=
x_out
)
model
.
compile
(
'
adam
'
,
loss
=
'
mse
'
)
model
.
compile
(
'
adam
'
,
loss
=
'
mse
'
)
model
.
summary
()
model
.
summary
()
# hist = model.fit(x, y, epochs=10)
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