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
920d6019
Commit
920d6019
authored
May 29, 2020
by
Tiago de Freitas Pereira
Browse files
Rethinking baselines
parent
1697a446
Pipeline
#40224
failed with stage
in 12 minutes and 31 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/bio/face/config/transformers/.DS_Store
0 → 100644
View file @
920d6019
File added
bob/bio/face/config/transformers/__init__.py
0 → 100644
View file @
920d6019
bob/bio/face/config/transformers/eyes_crop/facenet.py
0 → 100644
View file @
920d6019
import
bob.bio.face
from
sklearn.pipeline
import
make_pipeline
from
bob.bio.base.wrappers
import
wrap_sample_preprocessor
from
bob.pipelines
import
wrap
from
bob.bio.face.transformers
import
FaceNetSanderberg
# This is the size of the image that this model expects
CROPPED_IMAGE_HEIGHT
=
160
CROPPED_IMAGE_WIDTH
=
160
# eye positions for frontal images
RIGHT_EYE_POS
=
(
46
,
53
)
LEFT_EYE_POS
=
(
46
,
107
)
legacy_face_cropper
=
bob
.
bio
.
face
.
preprocessor
.
FaceCrop
(
cropped_image_size
=
(
CROPPED_IMAGE_HEIGHT
,
CROPPED_IMAGE_WIDTH
),
cropped_positions
=
{
"leye"
:
LEFT_EYE_POS
,
"reye"
:
RIGHT_EYE_POS
},
color_channel
=
"rgb"
,
)
embedding
=
FaceNetSanderberg
()
transformer
=
make_pipeline
(
wrap_sample_preprocessor
(
legacy_face_cropper
,
transform_extra_arguments
=
((
"annotations"
,
"annotations"
),),
),
wrap
([
"sample"
],
embedding
),
)
bob/bio/face/test/test_pipelines.py
0 → 100644
View file @
920d6019
from
bob.extension.config
import
load
import
pkg_resources
import
numpy
as
np
from
bob.pipelines
import
Sample
,
SampleSet
def
get_fake_sample
(
face_size
=
(
160
,
160
),
eyes
=
{
"leye"
:
(
46
,
107
),
"reye"
:
(
46
,
53
)}):
data
=
np
.
random
.
rand
(
3
,
400
,
400
)
annotations
=
{
"leye"
:
(
115
,
267
),
"reye"
:
(
115
,
132
)}
return
Sample
(
data
,
key
=
"1"
,
annotations
=
annotations
)
def
test_facenet_pipeline
():
config_name
=
pkg_resources
.
resource_filename
(
'bob.bio.face'
,
'config/transformers/eyes_crop/facenet.py'
)
transformer
=
load
([
config_name
]).
transformer
import
ipdb
;
ipdb
.
set_trace
()
fake_sample
=
get_fake_sample
()
transformed_sample
=
transformer
.
transform
([
fake_sample
])[
0
]
assert
transformed_sample
.
data
.
size
==
160
pass
\ No newline at end of file
bob/bio/face/transformers/facenet_sanderberg.py
View file @
920d6019
...
...
@@ -165,17 +165,25 @@ class FaceNetSanderberg(TransformerMixin, BaseEstimator):
logger
.
info
(
"Successfully loaded the model."
)
self
.
loaded
=
True
def
transform
(
self
,
img
):
images
=
self
.
_check_feature
(
img
)
if
not
self
.
loaded
:
self
.
load_model
()
feed_dict
=
{
self
.
images_placeholder
:
images
,
self
.
phase_train_placeholder
:
False
,
}
features
=
self
.
session
.
run
(
self
.
embeddings
,
feed_dict
=
feed_dict
)
return
features
.
flatten
()
def
transform
(
self
,
X
):
def
_transform
(
X
):
import
ipdb
;
ipdb
.
set_trace
()
images
=
self
.
_check_feature
(
X
)
if
not
self
.
loaded
:
self
.
load_model
()
feed_dict
=
{
self
.
images_placeholder
:
images
,
self
.
phase_train_placeholder
:
False
,
}
features
=
self
.
session
.
run
(
self
.
embeddings
,
feed_dict
=
feed_dict
)
return
features
.
flatten
()
if
isinstance
(
X
,
list
):
return
[
_transform
(
i
)
for
i
in
X
]
else
:
return
_transform
(
X
)
@
staticmethod
def
get_modelpath
():
...
...
@@ -214,3 +222,9 @@ class FaceNetSanderberg(TransformerMixin, BaseEstimator):
d
.
pop
(
"phase_train_placeholder"
)
if
"phase_train_placeholder"
in
d
else
None
tf
.
compat
.
v1
.
reset_default_graph
()
return
d
def
_more_tags
(
self
):
return
{
"stateless"
:
True
,
"requires_fit"
:
False
}
def
fit
(
self
,
X
,
y
=
None
):
return
self
bob/bio/face/transformers/tensorflow_compat_v1.py
View file @
920d6019
...
...
@@ -160,3 +160,11 @@ class TensorflowCompatV1(TransformerMixin, BaseEstimator):
bob
.
io
.
base
.
create_directories_safe
(
model_path
)
zip_file
=
os
.
path
.
join
(
model_path
,
zip_file
)
bob
.
extension
.
download
.
download_and_unzip
(
urls
,
zip_file
)
def
fit
(
self
,
X
,
y
=
None
):
return
self
def
_more_tags
(
self
):
return
{
"stateless"
:
True
,
"requires_fit"
:
False
}
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