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
f14e91b6
Commit
f14e91b6
authored
5 years ago
by
Felix Kleinert
Browse files
Options
Downloads
Patches
Plain Diff
split tests ins smaller subgroups
parent
2404827c
No related branches found
No related tags found
2 merge requests
!59
Develop
,
!46
Felix #56 advanced paddings
Pipeline
#30948
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
+295
-55
295 additions, 55 deletions
test/test_model_modules/test_advanced_paddings.py
with
295 additions
and
55 deletions
test/test_model_modules/test_advanced_paddings.py
+
295
−
55
View file @
f14e91b6
...
@@ -6,39 +6,51 @@ from src.model_modules.advanced_paddings import *
...
@@ -6,39 +6,51 @@ from src.model_modules.advanced_paddings import *
class
TestPadUtils
:
class
TestPadUtils
:
def
test_get_padding_for_same
(
self
):
def
test_get_padding_for_same_negative_kernel_size
(
self
):
with
pytest
.
raises
(
ValueError
):
print
(
'
In test_get_padding_for_same_negative_kernel_size
'
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
get_padding_for_same
((
-
1
,
2
))
PadUtils
.
get_padding_for_same
((
-
1
,
2
))
PadUtils
.
get_padding_for_same
((
1
,
0
)
)
assert
'
All values of kernel_size must be > 0. Got: (-1, 2)
'
in
str
(
einfo
.
value
)
kernel
=
(
1
,
1
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
pad
=
PadUtils
.
get_padding_for_same
(
kernel
)
PadUtils
.
get_padding_for_same
((
1
,
-
2
))
assert
pad
==
(
0
,
0
)
assert
'
All values of kernel_size must be > 0. Got: (1, -2)
'
in
str
(
einfo
.
value
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
assert
not
isinstance
(
pad
[
0
],
np
.
int64
)
with
pytest
.
raises
(
NotImplementedError
):
PadUtils
.
get_padding_for_same
(
kernel
,
strides
=
2
)
kernel
=
(
3
,
1
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
pad
=
PadUtils
.
get_padding_for_same
(
kernel
)
PadUtils
.
get_padding_for_same
((
-
1
,
-
2
))
assert
pad
==
(
1
,
0
)
assert
'
All values of kernel_size must be > 0. Got: (-1, -2)
'
in
str
(
einfo
.
value
)
assert
isinstance
(
pad
,
tuple
)
assert
isinstance
(
pad
[
0
],
int
)
and
isinstance
(
pad
[
1
],
int
)
def
test_get_padding_for_same_strides_greater_one
(
self
):
assert
not
isinstance
(
pad
[
0
],
np
.
int64
)
with
pytest
.
raises
(
NotImplementedError
)
as
einfo
:
PadUtils
.
get_padding_for_same
((
1
,
1
),
strides
=
2
)
assert
'
Strides other than 1 not implemented!
'
in
str
(
einfo
.
value
)
kernel
=
(
2
,
2
)
with
pytest
.
raises
(
NotImplementedError
)
as
einfo
:
with
pytest
.
raises
(
NotImplementedError
):
PadUtils
.
get_padding_for_same
((
1
,
1
),
strides
=-
1
)
PadUtils
.
get_padding_for_same
(
kernel
)
assert
'
Strides other than 1 not implemented!
'
in
str
(
einfo
.
value
)
def
test_get_padding_for_same_stride_3d
(
self
):
kernel
=
(
3
,
3
,
3
)
kernel
=
(
3
,
3
,
3
)
pad
=
PadUtils
.
get_padding_for_same
(
kernel
)
pad
=
PadUtils
.
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
[
1
],
np
.
int64
)
and
isinstance
(
pad
[
2
],
np
.
int64
))
def
test_get_padding_for_same_even_pad
(
self
):
with
pytest
.
raises
(
NotImplementedError
)
as
einfo
:
PadUtils
.
get_padding_for_same
((
2
,
1
))
assert
'
even kernel size not implemented. Got (2, 1)
'
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
NotImplementedError
)
as
einfo
:
PadUtils
.
get_padding_for_same
((
1
,
4
))
assert
'
even kernel size not implemented. Got (1, 4)
'
in
str
(
einfo
.
value
)
def
test_check_padding_format
(
self
):
with
pytest
.
raises
(
NotImplementedError
)
as
einfo
:
PadUtils
.
get_padding_for_same
((
2
,
4
))
assert
'
even kernel size not implemented. Got (2, 4)
'
in
str
(
einfo
.
value
)
def
test_check_padding_format_negative_pads
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
-
2
,
1
))
PadUtils
.
check_padding_format
((
-
2
,
1
))
...
@@ -46,12 +58,32 @@ class TestPadUtils:
...
@@ -46,12 +58,32 @@ class TestPadUtils:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1
,
-
1
))
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
)
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
((
-
2
,
-
1
))
assert
"
The `1st entry of padding` argument must be >= 0. Received: -2 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
def
test_check_padding_format_len_of_pad_tuple
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1
,
1
,
2
))
PadUtils
.
check_padding_format
((
1
,
1
,
2
))
assert
"
`padding` should have two elements. Found: (1, 1, 2)
"
in
str
(
einfo
.
value
)
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
,
1
,
2
,
2
))
assert
"
`padding` should have two elements. Found: (1, 1, 2, 2)
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1
,
1
,
3
),
(
2
,
2
,
4
)))
assert
"
`padding[0]` should have one or two elements. Found: (1, 1, 3)
"
in
str
(
einfo
.
value
)
assert
PadUtils
.
check_padding_format
(((
1
,
1
),
(
2
,
2
)))
==
((
1
,
1
),
(
2
,
2
))
assert
PadUtils
.
check_padding_format
((
1
,
2
))
==
((
1
,
1
),
(
2
,
2
))
assert
PadUtils
.
check_padding_format
(
1
)
==
((
1
,
1
),
(
1
,
1
))
def
test_check_padding_format_tupe_of_none_integer
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1.2
,
1
))
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
)
assert
"
The `1st entry of padding` argument must be a tuple of 2 integers. Received: 1.2
"
in
str
(
einfo
.
value
)
...
@@ -66,9 +98,56 @@ class TestPadUtils:
...
@@ -66,9 +98,56 @@ class TestPadUtils:
"
or a tuple of 2 tuples of 2 ints ((top_pad, bottom_pad), (left_pad, right_pad)). Found: 1.2 of type
"
\
"
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
)
"
<class
'
float
'
>
"
in
str
(
einfo
.
value
)
#
def
test_check_padding_format_tupe_of_tuple_none_integer_first
(
self
):
# def test_spatial_2d_padding(self):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
# pass
PadUtils
.
check_padding_format
(((
1.
,
2
),
(
3
,
4
)))
assert
"
`padding[0]` should have one or two elements of type int. Found:(1.0, 2)
"
\
"
of type [<class
'
float
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1
,
2.
),
(
3
,
4
)))
assert
"
`padding[0]` should have one or two elements of type int. Found:(1, 2.0)
"
\
"
of type [<class
'
int
'
>, <class
'
float
'
>]
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1
,
'
2
'
),
(
3
,
4
)))
assert
"
`padding[0]` should have one or two elements of type int. Found:(1,
'
2
'
)
"
\
"
of type [<class
'
int
'
>, <class
'
str
'
>]
"
in
str
(
einfo
.
value
)
def
test_check_padding_format_tupe_of_tuple_none_integer_second
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1
,
2
),
(
3.
,
4
)))
assert
"
`padding[1]` should have one or two elements of type int. Found:(3.0, 4)
"
\
"
of type [<class
'
float
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1
,
2
),
(
3
,
4.
)))
assert
"
`padding[1]` should have one or two elements of type int. Found:(3, 4.0)
"
\
"
of type [<class
'
int
'
>, <class
'
float
'
>]
"
in
str
(
einfo
.
value
)
def
test_check_padding_format_valid_mix_of_int_and_tuple
(
self
):
assert
PadUtils
.
check_padding_format
(((
1
,
2
),
3
))
==
((
1
,
2
),
(
3
,
3
))
assert
PadUtils
.
check_padding_format
((
1
,
(
2
,
3
)))
==
((
1
,
1
),
(
2
,
3
))
def
test_check_padding_format_invalid_mixed_tuple_and_int
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1.
,
2
),
3
))
assert
"
`padding[0]` should have one or two elements of type int. Found:(1.0, 2)
"
\
"
of type [<class
'
float
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
(((
1
,
2
),
3.
))
assert
"
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 3.0
"
in
str
(
einfo
.
value
)
def
test_check_padding_format_invalid_mixed_int_and_tuple
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
PadUtils
.
check_padding_format
((
1.
,
(
2
,
3
)))
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
:
PadUtils
.
check_padding_format
((
1
,
(
2.
,
3
)))
assert
"
`padding[1]` should have one or two elements of type int. Found:(2.0, 3)
"
\
"
of type [<class
'
float
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
class
TestReflectionPadding2D
:
class
TestReflectionPadding2D
:
...
@@ -77,36 +156,117 @@ class TestReflectionPadding2D:
...
@@ -77,36 +156,117 @@ class TestReflectionPadding2D:
def
input_x
(
self
):
def
input_x
(
self
):
return
keras
.
Input
(
shape
=
(
10
,
10
,
3
))
return
keras
.
Input
(
shape
=
(
10
,
10
,
3
))
def
test_init
(
self
):
def
test_init
_tuple_of_valid_int
(
self
):
pad
=
(
1
,
1
)
pad
=
(
1
,
3
)
layer_name
=
"
RefPAD
"
layer_name
=
"
RefPAD
"
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
ref_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
assert
ref_pad
.
padding
==
((
1
,
1
),
(
3
,
3
))
assert
ref_pad
.
name
==
'
RefPAD
'
assert
ref_pad
.
data_format
==
'
channels_last
'
assert
ref_pad
.
rank
==
2
pad
=
(
0
,
1
)
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
ref_pad
.
padding
==
((
0
,
0
),
(
1
,
1
))
assert
ref_pad
.
name
==
'
RefPAD
'
assert
ref_pad
.
name
==
'
RefPAD
'
assert
ref_pad
.
data_format
==
'
channels_last
'
assert
ref_pad
.
data_format
==
'
channels_last
'
assert
ref_pad
.
rank
==
2
assert
ref_pad
.
rank
==
2
pad
=
1
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
)
assert
ref_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
pad
=
(
5
,
3
)
pad
=
(
5
,
3
)
layer_name
=
"
RefPAD_5x3
"
layer_name
=
"
RefPAD_5x3
"
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
ref_pad
.
padding
==
((
5
,
5
),
(
3
,
3
))
assert
ref_pad
.
padding
==
((
5
,
5
),
(
3
,
3
))
pad
=
((
1
,
2
),
(
3
,
4
))
def
test_init_tuple_of_negative_int
(
self
):
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
assert
ref_pad
.
padding
==
((
1
,
2
),
(
3
,
4
))
ReflectionPadding2D
(
padding
=
(
-
1
,
1
))
assert
"
The `1st entry of padding` argument must be >= 0. Received: -1 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1.
,
2
))
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
)
assert
"
The `2nd entry of padding` argument must be >= 0. Received: -2 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
-
1
,
-
2
))
assert
"
The `1st entry of padding` argument must be >= 0. Received: -1 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
def
test_init_tuple_of_invalid_format_float
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1.
,
1
))
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
,
1.2
))
assert
'
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 1.2
'
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1.
,
1.2
))
assert
'
The `1st entry of padding` argument must be a tuple of 2 integers. Received: 1.0
'
in
str
(
einfo
.
value
)
def
test_init_tuple_of_invalid_format_string
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
'
1
'
,
2
))
# This error message is not the best as it is missing the type information.
# But it is raised by keras.utils.conv_utils which I will not touch.
assert
"
`padding[0]` is str but must be int
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1
,
'
2
'
))
assert
'
`padding[1]` is str but must be int
'
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
'
1
'
,
'
2
'
))
assert
'
`padding[0]` is str but must be int
'
in
str
(
einfo
.
value
)
def
test_init_int
(
self
):
layer_name
=
"
RefPAD
"
ref_pad
=
ReflectionPadding2D
(
padding
=
1
,
name
=
layer_name
)
assert
ref_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
assert
ref_pad
.
name
==
"
RefPAD
"
def
test_init_tuple_of_tuple_of_valid_int
(
self
):
ref_pad
=
ReflectionPadding2D
(
padding
=
((
0
,
1
),
(
2
,
3
)),
name
=
"
RefPAD
"
)
assert
ref_pad
.
padding
==
((
0
,
1
),
(
2
,
3
))
assert
ref_pad
.
name
==
"
RefPAD
"
def
test_init_tuple_of_tuple_of_invalid_int
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
((
-
4
,
1
),
(
2
,
3
)),
name
=
"
RefPAD
"
)
assert
"
The `1st entry of padding` argument must be >= 0. Received: (-4, 1) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
((
4
,
-
1
),
(
2
,
3
)),
name
=
"
RefPAD
"
)
assert
"
The `1st entry of padding` argument must be >= 0. Received: (4, -1) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
((
4
,
1
),
(
-
2
,
3
)),
name
=
"
RefPAD
"
)
assert
"
The `2nd entry of padding` argument must be >= 0. Received: (-2, 3) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
((
4
,
1
),
(
2
,
-
3
)),
name
=
"
RefPAD
"
)
assert
"
The `2nd entry of padding` argument must be >= 0. Received: (2, -3) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
def
test_init_tuple_of_tuple_of_invalid_format
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
((
0.1
,
1
),
(
2
,
3
)),
name
=
"
RefPAD
"
)
assert
"
`padding[0]` should have one or two elements of type int. Found:(0.1, 1)
"
\
"
of type [<class
'
float
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
(
1
,
2.2
))
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
)
assert
"
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 2.2
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
ReflectionPadding2D
(
padding
=
((
0
,
1
),
(
'
2
'
,
3
)),
name
=
"
RefPAD
"
)
assert
"
`padding[1]` should have one or two elements of type int. Found:(
'
2
'
, 3)
"
\
"
of type [<class
'
str
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
def
test_call
(
self
,
input_x
):
def
test_call
(
self
,
input_x
):
# here it behaves like a "normal" keras layer, I don't know how to test those
pad
=
(
1
,
0
)
pad
=
(
1
,
0
)
layer_name
=
"
RefPad_3x1
"
layer_name
=
"
RefPad_3x1
"
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)(
input_x
)
ref_pad
=
ReflectionPadding2D
(
padding
=
pad
,
name
=
layer_name
)(
input_x
)
...
@@ -120,42 +280,122 @@ class TestSymmerticPadding2D:
...
@@ -120,42 +280,122 @@ class TestSymmerticPadding2D:
def
input_x
(
self
):
def
input_x
(
self
):
return
keras
.
Input
(
shape
=
(
10
,
10
,
3
))
return
keras
.
Input
(
shape
=
(
10
,
10
,
3
))
def
test_init
(
self
):
def
test_init
_tuple_of_valid_int
(
self
):
pad
=
(
1
,
1
)
pad
=
(
1
,
3
)
layer_name
=
"
SymP
AD
"
layer_name
=
"
SymP
ad
"
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
sym_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
assert
sym_pad
.
padding
==
((
1
,
1
),
(
3
,
3
))
assert
sym_pad
.
name
==
'
SymPAD
'
assert
sym_pad
.
name
==
'
SymPad
'
assert
sym_pad
.
data_format
==
'
channels_last
'
assert
sym_pad
.
rank
==
2
pad
=
(
0
,
1
)
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
sym_pad
.
padding
==
((
0
,
0
),
(
1
,
1
))
assert
sym_pad
.
name
==
'
SymPad
'
assert
sym_pad
.
data_format
==
'
channels_last
'
assert
sym_pad
.
data_format
==
'
channels_last
'
assert
sym_pad
.
rank
==
2
assert
sym_pad
.
rank
==
2
pad
=
1
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
)
assert
sym_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
pad
=
(
5
,
3
)
pad
=
(
5
,
3
)
layer_name
=
"
SymP
AD
_5x3
"
layer_name
=
"
SymP
ad
_5x3
"
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)
assert
sym_pad
.
padding
==
((
5
,
5
),
(
3
,
3
))
assert
sym_pad
.
padding
==
((
5
,
5
),
(
3
,
3
))
pad
=
((
1
,
2
),
(
3
,
4
))
def
test_init_tuple_of_negative_int
(
self
):
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
assert
sym_pad
.
padding
==
((
1
,
2
),
(
3
,
4
))
SymmetricPadding2D
(
padding
=
(
-
1
,
1
))
assert
"
The `1st entry of padding` argument must be >= 0. Received: -1 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1.
,
2
))
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
)
assert
"
The `2nd entry of padding` argument must be >= 0. Received: -2 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
-
1
,
-
2
))
assert
"
The `1st entry of padding` argument must be >= 0. Received: -1 of type <class
'
int
'
>
"
in
str
(
einfo
.
value
)
def
test_init_tuple_of_invalid_format_float
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1.
,
1
))
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
,
1.2
))
assert
'
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 1.2
'
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1.
,
1.2
))
assert
'
The `1st entry of padding` argument must be a tuple of 2 integers. Received: 1.0
'
in
str
(
einfo
.
value
)
def
test_init_tuple_of_invalid_format_string
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
'
1
'
,
2
))
# This error message is not the best as it is missing the type information.
# But it is raised by keras.utils.conv_utils which I will not touch.
assert
"
`padding[0]` is str but must be int
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1
,
'
2
'
))
assert
'
`padding[1]` is str but must be int
'
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
'
1
'
,
'
2
'
))
assert
'
`padding[0]` is str but must be int
'
in
str
(
einfo
.
value
)
def
test_init_int
(
self
):
layer_name
=
"
SymPad
"
sym_pad
=
SymmetricPadding2D
(
padding
=
1
,
name
=
layer_name
)
assert
sym_pad
.
padding
==
((
1
,
1
),
(
1
,
1
))
assert
sym_pad
.
name
==
"
SymPad
"
def
test_init_tuple_of_tuple_of_valid_int
(
self
):
sym_pad
=
SymmetricPadding2D
(
padding
=
((
0
,
1
),
(
2
,
3
)),
name
=
"
SymPad
"
)
assert
sym_pad
.
padding
==
((
0
,
1
),
(
2
,
3
))
assert
sym_pad
.
name
==
"
SymPad
"
def
test_init_tuple_of_tuple_of_invalid_int
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
((
-
4
,
1
),
(
2
,
3
)),
name
=
"
SymPad
"
)
assert
"
The `1st entry of padding` argument must be >= 0. Received: (-4, 1) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
((
4
,
-
1
),
(
2
,
3
)),
name
=
"
SymPad
"
)
assert
"
The `1st entry of padding` argument must be >= 0. Received: (4, -1) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
((
4
,
1
),
(
-
2
,
3
)),
name
=
"
SymPad
"
)
assert
"
The `2nd entry of padding` argument must be >= 0. Received: (-2, 3) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
((
4
,
1
),
(
2
,
-
3
)),
name
=
"
SymPad
"
)
assert
"
The `2nd entry of padding` argument must be >= 0. Received: (2, -3) of type <class
'
tuple
'
>
"
in
str
(
einfo
.
value
)
def
test_init_tuple_of_tuple_of_invalid_format
(
self
):
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
((
0.1
,
1
),
(
2
,
3
)),
name
=
"
SymPad
"
)
assert
"
`padding[0]` should have one or two elements of type int. Found:(0.1, 1)
"
\
"
of type [<class
'
float
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
(
1
,
2.2
))
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
)
assert
"
The `2nd entry of padding` argument must be a tuple of 2 integers. Received: 2.2
"
in
str
(
einfo
.
value
)
with
pytest
.
raises
(
ValueError
)
as
einfo
:
SymmetricPadding2D
(
padding
=
((
0
,
1
),
(
'
2
'
,
3
)),
name
=
"
SymPad
"
)
assert
"
`padding[1]` should have one or two elements of type int. Found:(
'
2
'
, 3)
"
\
"
of type [<class
'
str
'
>, <class
'
int
'
>]
"
in
str
(
einfo
.
value
)
def
test_call
(
self
,
input_x
):
def
test_call
(
self
,
input_x
):
# here it behaves like a "normal" keras layer, I don't know how to test those
pad
=
(
1
,
0
)
pad
=
(
1
,
0
)
layer_name
=
"
SymPad_3x1
"
layer_name
=
"
SymPad_3x1
"
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)(
input_x
)
sym_pad
=
SymmetricPadding2D
(
padding
=
pad
,
name
=
layer_name
)(
input_x
)
assert
sym_pad
.
get_shape
().
as_list
()
==
[
None
,
12
,
10
,
3
]
assert
sym_pad
.
get_shape
().
as_list
()
==
[
None
,
12
,
10
,
3
]
assert
sym_pad
.
name
==
'
SymPad_3x1/MirrorPad:0
'
assert
sym_pad
.
name
==
'
SymPad_3x1/MirrorPad:0
'
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