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
f38b1cfd
Commit
f38b1cfd
authored
5 years ago
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
update some tests for advanced paddings (
#56
)
parent
abef8764
No related branches found
No related tags found
2 merge requests
!59
Develop
,
!46
Felix #56 advanced paddings
Pipeline
#30913
passed
5 years ago
Stage: test
Stage: pages
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_model_modules/test_advanced_paddings.py
+125
-7
125 additions, 7 deletions
test/test_model_modules/test_advanced_paddings.py
with
125 additions
and
7 deletions
test/test_model_modules/test_advanced_paddings.py
+
125
−
7
View file @
f38b1cfd
import
keras
import
keras
import
tensorflow
as
tf
import
numpy
as
np
import
numpy
as
np
import
pytest
import
pytest
import
mock
import
mock
...
@@ -11,20 +12,20 @@ class TestPadUtils:
...
@@ -11,20 +12,20 @@ class TestPadUtils:
def
test_get_padding_for_same
(
self
):
def
test_get_padding_for_same
(
self
):
with
pytest
.
raises
(
ValueError
):
with
pytest
.
raises
(
ValueError
):
p
ad
_u
tils
.
get_padding_for_same
((
-
1
,
2
))
P
ad
U
tils
.
get_padding_for_same
((
-
1
,
2
))
p
ad
_u
tils
.
get_padding_for_same
((
1
,
0
))
P
ad
U
tils
.
get_padding_for_same
((
1
,
0
))
kernel
=
(
1
,
1
)
kernel
=
(
1
,
1
)
pad
=
p
ad
_u
tils
.
get_padding_for_same
(
kernel
)
pad
=
P
ad
U
tils
.
get_padding_for_same
(
kernel
)
assert
pad
==
(
0
,
0
)
assert
pad
==
(
0
,
0
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
assert
not
isinstance
(
pad
[
0
],
np
.
int64
)
assert
not
isinstance
(
pad
[
0
],
np
.
int64
)
with
pytest
.
raises
(
NotImplementedError
):
with
pytest
.
raises
(
NotImplementedError
):
p
ad
_u
tils
.
get_padding_for_same
(
kernel
,
strides
=
2
)
P
ad
U
tils
.
get_padding_for_same
(
kernel
,
strides
=
2
)
kernel
=
(
3
,
1
)
kernel
=
(
3
,
1
)
pad
=
p
ad
_u
tils
.
get_padding_for_same
(
kernel
)
pad
=
P
ad
U
tils
.
get_padding_for_same
(
kernel
)
assert
pad
==
(
1
,
0
)
assert
pad
==
(
1
,
0
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
...
@@ -32,15 +33,132 @@ class TestPadUtils:
...
@@ -32,15 +33,132 @@ class TestPadUtils:
kernel
=
(
2
,
2
)
kernel
=
(
2
,
2
)
with
pytest
.
raises
(
NotImplementedError
):
with
pytest
.
raises
(
NotImplementedError
):
p
ad
_u
tils
.
get_padding_for_same
(
kernel
)
P
ad
U
tils
.
get_padding_for_same
(
kernel
)
kernel
=
(
3
,
3
,
3
)
kernel
=
(
3
,
3
,
3
)
pad
=
p
ad
_u
tils
.
get_padding_for_same
(
kernel
)
pad
=
P
ad
U
tils
.
get_padding_for_same
(
kernel
)
assert
pad
==
(
1
,
1
,
1
)
assert
pad
==
(
1
,
1
,
1
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
assert
not
(
isinstance
(
pad
[
0
],
np
.
int64
)
and
isinstance
(
pad
[
0
],
np
.
int64
))
assert
not
(
isinstance
(
pad
[
0
],
np
.
int64
)
and
isinstance
(
pad
[
0
],
np
.
int64
))
def
test_check_padding_format
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
-
2
,
1
))
assert
"
The `1st entry of padding` argument must be >= 0. Received: -2 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1
,
-
1
))
assert
"
The `2nd entry of padding` argument must be >= 0. Received: -1 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1
,
1
,
2
))
assert
"
`padding` should have two elements. Found: (1, 1, 2)
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1.2
,
1
))
assert
"
The `1st entry of padding` argument must be a tuple of 2 integers. Received: 1.2
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1
,
1.
))
assert
"
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 1.0
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(
1.2
)
assert
"
`padding` should be either an int, a tuple of 2 ints (symmetric_height_pad, symmetric_width_pad),
"
\
"
or a tuple of 2 tuples of 2 ints ((top_pad, bottom_pad), (left_pad, right_pad)). Found: 1.2 of type
"
\
"
<class
'
float
'
>
"
in
str
(
einfo
.
value
)
#
# def test_spatial_2d_padding(self):
# pass
class
TestReflectionPadding2D
:
@pytest.fixture
def
input_x
(
self
):
return
keras
.
Input
(
shape
=
(
10
,
10
,
3
))
def
test_init
(
self
):
pad
=
(
1
,
1
)
layer_name
=
"
RefPAD
"
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
ref_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
assert
ref_pad
.
name
==
'
RefPAD
'
assert
ref_pad
.
data_format
==
'
channels_last
'
assert
ref_pad
.
rank
==
2
pad
=
1
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
)
assert
ref_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
pad
=
(
5
,
3
)
layer_name
=
"
RefPAD_5x3
"
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
ref_pad
.
padding
==
((
5
,
5
),
(
3
,
3
))
pad
=
((
1
,
2
),
(
3
,
4
))
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
)
assert
ref_pad
.
padding
==
((
1
,
2
),
(
3
,
4
))
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1.
,
2
))
assert
"
The `1st entry of padding` argument must be a tuple of 2 integers. Received: 1.0
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1
,
2.2
))
assert
"
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 2.2
"
in
str
(
einfo
.
value
)
def
test_call
(
self
,
input_x
):
pad
=
(
1
,
0
)
layer_name
=
"
RefPad_3x1
"
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)(
input_x
)
assert
ref_pad
.
get_shape
().
as_list
()
==
[
None
,
12
,
10
,
3
]
assert
ref_pad
.
name
==
'
RefPad_3x1/MirrorPad:0
'
class
TestSymmerticPadding2D
:
@pytest.fixture
def
input_x
(
self
):
return
keras
.
Input
(
shape
=
(
10
,
10
,
3
))
def
test_init
(
self
):
pad
=
(
1
,
1
)
layer_name
=
"
SymPAD
"
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
sym_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
assert
sym_pad
.
name
==
'
SymPAD
'
assert
sym_pad
.
data_format
==
'
channels_last
'
assert
sym_pad
.
rank
==
2
pad
=
1
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
)
assert
sym_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
pad
=
(
5
,
3
)
layer_name
=
"
SymPAD_5x3
"
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
sym_pad
.
padding
==
((
5
,
5
),
(
3
,
3
))
pad
=
((
1
,
2
),
(
3
,
4
))
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
)
assert
sym_pad
.
padding
==
((
1
,
2
),
(
3
,
4
))
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1.
,
2
))
assert
"
The `1st entry of padding` argument must be a tuple of 2 integers. Received: 1.0
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1
,
2.2
))
assert
"
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 2.2
"
in
str
(
einfo
.
value
)
def
test_call
(
self
,
input_x
):
pad
=
(
1
,
0
)
layer_name
=
"
SymPad_3x1
"
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)(
input_x
)
assert
sym_pad
.
get_shape
().
as_list
()
==
[
None
,
12
,
10
,
3
]
assert
sym_pad
.
name
==
'
SymPad_3x1/MirrorPad:0
'
print
(
123
)
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