Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.bio.face
Commits
6e4cddfa
Commit
6e4cddfa
authored
May 27, 2020
by
Tiago de Freitas Pereira
Browse files
Fixed picklable tests
parent
9a106e8c
Pipeline
#40169
failed with stage
in 4 minutes and 35 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/bio/face/extractor/GridGraph.py
View file @
6e4cddfa
...
...
@@ -139,11 +139,19 @@ class GridGraph(Extractor):
raise
ValueError
(
"Please specify either 'eyes' or the grid parameters 'node_distance' (and 'first_node')!"
)
self
.
_aligned_graph
=
None
self
.
_last_image_resolution
=
None
if
not
hasattr
(
self
,
"_last_image_resolution"
):
self
.
_last_image_resolution
=
None
if
not
hasattr
(
self
,
"_aligned_graph"
):
self
.
_aligned_graph
=
None
if
isinstance
(
self
.
node_distance
,
(
int
,
float
)):
self
.
node_distance
=
(
int
(
self
.
node_distance
),
int
(
self
.
node_distance
))
self
.
_graph
=
None
def
_extractor
(
self
,
image
):
"""Creates an extractor based on the given image.
If an aligned graph was specified in the constructor, it is simply returned.
...
...
bob/bio/face/test/test_picklability.py
View file @
6e4cddfa
import
bob.bio.face
import
bob.bio.base
from
bob.pipelines.utils
import
assert_picklable
import
numpy
import
numpy
as
np
import
pickle
import
nose
import
bob.ip.base
import
bob.ip.flandmark
import
bob.ip.gabor
def
assert_picklable_with_exceptions
(
obj
):
"""Test if an object is picklable or not."""
# some bob C bind objects doesn't have __eq__ properly implemented
# and we'll not implement it
# therefore, exception list has been done, so we can skip
# those objects
exception_list
=
[
bob
.
ip
.
base
.
LBP
,
bob
.
bio
.
face
.
preprocessor
.
FaceCrop
,
bob
.
ip
.
facedetect
.
detector
.
sampler
.
Sampler
,
bob
.
ip
.
facedetect
.
detector
.
cascade
.
Cascade
,
bob
.
ip
.
flandmark
.
Flandmark
,
bob
.
ip
.
gabor
.
Similarity
,
bob
.
ip
.
gabor
.
Transform
,
bob
.
ip
.
gabor
.
Graph
,
]
string
=
pickle
.
dumps
(
obj
)
new_obj
=
pickle
.
loads
(
string
)
obj
=
obj
.
__dict__
new_obj
=
new_obj
.
__dict__
assert
len
(
obj
)
==
len
(
new_obj
)
nose
.
tools
.
assert_equal
(
sorted
(
list
(
obj
.
keys
())),
sorted
(
list
(
new_obj
.
keys
())))
for
k
,
v
in
obj
.
items
():
if
isinstance
(
v
,
np
.
ndarray
):
np
.
testing
.
assert_equal
(
v
,
new_obj
[
k
])
else
:
if
type
(
v
)
not
in
exception_list
:
nose
.
tools
.
assert_equal
(
v
,
new_obj
[
k
])
return
True
### Preprocessors
...
...
@@ -17,41 +56,41 @@ def test_face_crop():
color_channel
=
"rgb"
,
dtype
=
"uint8"
,
)
assert
assert_picklable
(
cropper
)
assert
assert_picklable
_with_exceptions
(
cropper
)
def
test_face_detect
():
face_detect
=
bob
.
bio
.
face
.
preprocessor
.
FaceDetect
(
face_cropper
=
"face-crop-eyes"
)
assert_picklable
(
face_detect
)
assert_picklable
_with_exceptions
(
face_detect
)
face_detect
=
bob
.
bio
.
face
.
preprocessor
.
FaceDetect
(
face_cropper
=
"face-crop-eyes"
,
use_flandmark
=
True
)
assert
assert_picklable
(
face_detect
)
assert
assert_picklable
_with_exceptions
(
face_detect
)
def
test_INormLBP
():
face_crop
=
bob
.
bio
.
face
.
preprocessor
.
INormLBP
(
face_cropper
=
"face-crop-eyes"
)
assert
assert_picklable
(
face_crop
)
assert
assert_picklable
_with_exceptions
(
face_crop
)
def
test_TanTriggs
():
face_crop
=
bob
.
bio
.
face
.
preprocessor
.
TanTriggs
(
face_cropper
=
"face-crop-eyes"
)
assert
assert_picklable
(
face_crop
)
assert
assert_picklable
_with_exceptions
(
face_crop
)
def
test_SQI
():
face_crop
=
bob
.
bio
.
face
.
preprocessor
.
SelfQuotientImage
(
face_cropper
=
"face-crop-eyes"
)
assert
assert_picklable
(
face_crop
)
assert
assert_picklable
_with_exceptions
(
face_crop
)
def
test_HistogramEqualization
():
face_crop
=
bob
.
bio
.
face
.
preprocessor
.
HistogramEqualization
(
face_cropper
=
"face-crop-eyes"
)
assert
assert_picklable
(
face_crop
)
assert
assert_picklable
_with_exceptions
(
face_crop
)
### Extractors
...
...
@@ -59,27 +98,23 @@ def test_HistogramEqualization():
def
test_DCT
():
extractor
=
bob
.
bio
.
face
.
extractor
.
DCTBlocks
()
assert_picklable
(
extractor
)
assert_picklable
_with_exceptions
(
extractor
)
def
test_GridGraph
():
def
test_GridGraph
():
extractor
=
bob
.
bio
.
face
.
extractor
.
GridGraph
(
node_distance
=
24
)
assert
assert_picklable
(
extractor
)
#
assert assert_picklable
_with_exceptions
(extractor)
fake_image
=
n
umpy
.
arange
(
64
*
80
).
reshape
(
64
,
80
).
astype
(
"float"
)
fake_image
=
n
p
.
arange
(
64
*
80
).
reshape
(
64
,
80
).
astype
(
"float"
)
extractor
(
fake_image
)
assert
assert_picklable
(
extractor
)
cropper
=
bob
.
bio
.
base
.
load_resource
(
"face-crop-eyes"
,
"preprocessor"
,
preferred_package
=
"bob.bio.face"
)
eyes
=
cropper
.
cropped_positions
extractor
=
bob
.
bio
.
face
.
extractor
.
GridGraph
(
eyes
=
eyes
)
assert
assert_picklable
(
extractor
)
assert
assert_picklable_with_exceptions
(
extractor
)
#cropper = bob.bio.base.load_resource(
# "face-crop-eyes", "preprocessor", preferred_package="bob.bio.face"
#)
#eyes = cropper.cropped_positions
#extractor = bob.bio.face.extractor.GridGraph(eyes=eyes)
#assert assert_picklable_with_exceptions(extractor)
def
test_LGBPHS
():
...
...
@@ -94,7 +129,7 @@ def test_LGBPHS():
sparse_histogram
=
True
,
)
assert
assert_picklable
(
extractor
)
assert
assert_picklable
_with_exceptions
(
extractor
)
## Algorithms
...
...
@@ -105,9 +140,9 @@ def test_GaborJet():
algorithm
=
bob
.
bio
.
face
.
algorithm
.
GaborJet
(
"PhaseDiffPlusCanberra"
,
multiple_feature_scoring
=
"average_model"
)
assert
assert_picklable
(
algorithm
)
assert
assert_picklable
_with_exceptions
(
algorithm
)
def
test_Histogram
():
algorithm
=
bob
.
bio
.
face
.
algorithm
.
Histogram
()
assert
assert_picklable
(
algorithm
)
assert
assert_picklable
_with_exceptions
(
algorithm
)
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