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
4d3e7ce8
Commit
4d3e7ce8
authored
Jun 10, 2020
by
Tiago de Freitas Pereira
Browse files
Added arcface
parent
fa53a59d
Changes
4
Hide whitespace changes
Inline
Side-by-side
bob/bio/face/config/baseline/arcface_insight_tf.py
0 → 100644
View file @
4d3e7ce8
from
bob.bio.face.embeddings
import
ArcFace_InsightFaceTF
from
bob.bio.face.config.baseline.helpers
import
embedding_transformer_112x112
if
"database"
in
locals
():
annotation_type
=
database
.
annotation_type
fixed_positions
=
database
.
fixed_positions
else
:
annotation_type
=
None
fixed_positions
=
None
transformer
=
embedding_transformer_112x112
(
ArcFace_InsightFaceTF
(),
annotation_type
,
fixed_positions
)
bob/bio/face/config/baseline/helpers.py
View file @
4d3e7ce8
...
...
@@ -64,3 +64,64 @@ def embedding_transformer_160x160(embedding, annotation_type, fixed_positions):
)
return
transformer
def
embedding_transformer_112x112
(
embedding
,
annotation_type
,
fixed_positions
):
"""
Creates a pipeline composed by and FaceCropper and an Embedding extractor.
This transformer is suited for Facenet based architectures
.. warning::
This will redirect images to :math:`160
\t
imes 160`
"""
# This is the size of the image that this model expects
CROPPED_IMAGE_HEIGHT
=
112
CROPPED_IMAGE_WIDTH
=
112
cropped_image_size
=
(
CROPPED_IMAGE_HEIGHT
,
CROPPED_IMAGE_WIDTH
)
color_channel
=
"rgb"
#### SOLVING THE FACE CROPPER TO BE USED
if
annotation_type
==
"bounding-box"
:
transform_extra_arguments
=
((
"annotations"
,
"annotations"
),)
TOP_LEFT_POS
=
(
0
,
0
)
BOTTOM_RIGHT_POS
=
(
CROPPED_IMAGE_HEIGHT
,
CROPPED_IMAGE_WIDTH
)
# Detects the face and crops it without eye detection
face_cropper
=
face_crop_solver
(
cropped_image_size
,
color_channel
=
color_channel
,
cropped_positions
=
{
"topleft"
:
TOP_LEFT_POS
,
"bottomright"
:
BOTTOM_RIGHT_POS
},
fixed_positions
=
fixed_positions
,
)
elif
annotation_type
==
"eyes-center"
:
transform_extra_arguments
=
((
"annotations"
,
"annotations"
),)
# eye positions for frontal images
RIGHT_EYE_POS
=
(
32
,
34
)
LEFT_EYE_POS
=
(
32
,
77
)
# Detects the face and crops it without eye detection
face_cropper
=
face_crop_solver
(
cropped_image_size
,
color_channel
=
color_channel
,
cropped_positions
=
{
"leye"
:
LEFT_EYE_POS
,
"reye"
:
RIGHT_EYE_POS
},
fixed_positions
=
fixed_positions
,
)
else
:
transform_extra_arguments
=
None
# DEFAULT TO FACE SIMPLE RESIZE
face_cropper
=
face_crop_solver
(
cropped_image_size
)
transformer
=
make_pipeline
(
wrap
(
[
"sample"
],
face_cropper
,
transform_extra_arguments
=
transform_extra_arguments
,
),
wrap
([
"sample"
],
embedding
),
)
return
transformer
bob/bio/face/embeddings/arface.py
View file @
4d3e7ce8
...
...
@@ -40,7 +40,6 @@ class ArcFace_InsightFaceTF(TensorflowCompatV1):
# https://github.com/luckycallor/InsightFace-tensorflow/blob/master/evaluate.py#L42
data
=
check_array
(
data
,
allow_nd
=
True
)
data
=
data
/
127.5
-
1.0
return
super
().
transform
(
data
)
def
load_model
(
self
):
...
...
bob/bio/face/test/test_baseline.py
View file @
4d3e7ce8
...
...
@@ -74,3 +74,19 @@ def test_inception_resnetv1_casiawebface():
transformed_sample
=
transformer
.
transform
([
fake_sample
])[
0
]
transformed_data
=
transformed_sample
.
data
assert
transformed_sample
.
data
.
size
==
128
def
test_arcface_insight_tf
():
import
tensorflow
as
tf
tf
.
compat
.
v1
.
reset_default_graph
()
config_name
=
pkg_resources
.
resource_filename
(
"bob.bio.face"
,
"config/baseline/arcface_insight_tf.py"
)
transformer
=
load
([
config_name
]).
transformer
fake_sample
=
get_fake_sample
()
transformed_sample
=
transformer
.
transform
([
fake_sample
])[
0
]
transformed_data
=
transformed_sample
.
data
assert
transformed_sample
.
data
.
size
==
512
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