Skip to content
Snippets Groups Projects
Commit c2a907cc authored by Laurent COLBOIS's avatar Laurent COLBOIS
Browse files

Regrouping config helper modules

parent 6f5e3a4f
No related branches found
No related tags found
1 merge request!119Refactor baseline config helpers
import bob.bio.face import bob.bio.face
from bob.bio.face.preprocessor import FaceCrop, MultiFaceCrop, Scale
from sklearn.pipeline import make_pipeline from sklearn.pipeline import make_pipeline
from bob.bio.base.wrappers import wrap_sample_preprocessor from bob.bio.base.wrappers import wrap_sample_preprocessor
from bob.pipelines import wrap from bob.pipelines import wrap
from bob.bio.face.helpers import face_crop_solver
import numpy as np import numpy as np
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def face_crop_solver(
cropped_image_size,
cropped_positions=None,
color_channel="rgb",
fixed_positions=None,
annotator=None,
dtype="uint8",
):
"""
Decide which face cropper to use.
"""
# If there's not cropped positions, just resize
if cropped_positions is None:
return Scale(cropped_image_size)
else:
# Detects the face and crops it without eye detection
if isinstance(cropped_positions, list):
return MultiFaceCrop(
cropped_image_size=cropped_image_size,
cropped_positions_list=cropped_positions,
fixed_positions_list=fixed_positions,
color_channel=color_channel,
dtype=dtype,
annotation=annotator,
)
else:
return FaceCrop(
cropped_image_size=cropped_image_size,
cropped_positions=cropped_positions,
color_channel=color_channel,
fixed_positions=fixed_positions,
dtype=dtype,
annotator=annotator,
)
def embedding_transformer_default_cropping(cropped_image_size, annotation_type): def embedding_transformer_default_cropping(cropped_image_size, annotation_type):
""" """
Computes the default cropped positions for the FaceCropper used with Facenet-like Computes the default cropped positions for the FaceCropper used with Facenet-like
......
from bob.bio.face.preprocessor import FaceCrop, MultiFaceCrop, Scale
def face_crop_solver(
cropped_image_size,
cropped_positions=None,
color_channel="rgb",
fixed_positions=None,
annotator=None,
dtype="uint8",
):
"""
Decide which face cropper to use.
"""
# If there's not cropped positions, just resize
if cropped_positions is None:
return Scale(cropped_image_size)
else:
# Detects the face and crops it without eye detection
if isinstance(cropped_positions, list):
return MultiFaceCrop(
cropped_image_size=cropped_image_size,
cropped_positions_list=cropped_positions,
fixed_positions_list=fixed_positions,
color_channel=color_channel,
dtype=dtype,
annotation=annotator,
)
else:
return FaceCrop(
cropped_image_size=cropped_image_size,
cropped_positions=cropped_positions,
color_channel=color_channel,
fixed_positions=fixed_positions,
dtype=dtype,
annotator=annotator,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment