From c243d2ce6c8ba03acf76686997bcb6a773a44f66 Mon Sep 17 00:00:00 2001 From: Olegs NIKISINS <onikisins@italix03.idiap.ch> Date: Thu, 24 May 2018 16:28:40 +0200 Subject: [PATCH] Fixed the load method in HLDI of CelebA, added BW face cropper --- bob/pad/face/config/celeb_a.py | 10 ++++---- .../config/preprocessor/video_face_crop.py | 24 ++++++++++++++++++- bob/pad/face/database/celeb_a.py | 9 ++++--- setup.py | 1 + 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/bob/pad/face/config/celeb_a.py b/bob/pad/face/config/celeb_a.py index 6bc9e6e0..6e17727c 100644 --- a/bob/pad/face/config/celeb_a.py +++ b/bob/pad/face/config/celeb_a.py @@ -13,16 +13,16 @@ from bob.pad.face.database.celeb_a import CELEBAPadDatabase # Directory where the data files are stored. # This directory is given in the .bob_bio_databases.txt file located in your home directory -original_directory = "[YOUR_CELEB_A_DATABASE_DIRECTORY]" +ORIGINAL_DIRECTORY = "[YOUR_CELEB_A_DATABASE_DIRECTORY]" """Value of ``~/.bob_bio_databases.txt`` for this database""" -original_extension = "" # extension of the data files +ORIGINAL_EXTENSION = "" # extension of the data files database = CELEBAPadDatabase( protocol='grandtest', - original_directory=original_directory, - original_extension=original_extension, - training_depends_on_protocol=True, + original_directory=ORIGINAL_DIRECTORY, + original_extension=ORIGINAL_EXTENSION, + training_depends_on_protocol=True ) """The :py:class:`bob.pad.base.database.PadDatabase` derivative with CELEBA database settings. diff --git a/bob/pad/face/config/preprocessor/video_face_crop.py b/bob/pad/face/config/preprocessor/video_face_crop.py index 924ada95..5bcd67d1 100644 --- a/bob/pad/face/config/preprocessor/video_face_crop.py +++ b/bob/pad/face/config/preprocessor/video_face_crop.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- -from ..preprocessor import FaceCropAlign +from bob.pad.face.preprocessor import FaceCropAlign from bob.bio.video.preprocessor import Wrapper @@ -42,3 +42,25 @@ _image_preprocessor = FaceCropAlign(face_size=FACE_SIZE, rgb_face_detector_mtcnn = Wrapper(preprocessor = _image_preprocessor, frame_selector = _frame_selector) + +# ======================================================================================= +FACE_SIZE = 64 # The size of the resulting face +RGB_OUTPUT_FLAG = False # Gray-scale output +USE_FACE_ALIGNMENT = True # detect face landmarks locally and align the face +MAX_IMAGE_SIZE = 1920 # the largest possible dimension of the input image +FACE_DETECTION_METHOD = "mtcnn" # face landmarks detection method +MIN_FACE_SIZE = 50 # skip faces smaller than this value +NORMALIZATION_FUNCTION = None # no normalization +NORMALIZATION_FUNCTION_KWARGS = None + +_image_preprocessor = FaceCropAlign(face_size=FACE_SIZE, + rgb_output_flag=RGB_OUTPUT_FLAG, + use_face_alignment=USE_FACE_ALIGNMENT, + max_image_size=MAX_IMAGE_SIZE, + face_detection_method=FACE_DETECTION_METHOD, + min_face_size=MIN_FACE_SIZE, + normalization_function=NORMALIZATION_FUNCTION, + normalization_function_kwargs=NORMALIZATION_FUNCTION_KWARGS) + +bw_face_detect_mtcnn = Wrapper(preprocessor=_image_preprocessor, + frame_selector=_frame_selector) diff --git a/bob/pad/face/database/celeb_a.py b/bob/pad/face/database/celeb_a.py index fb37378e..3fc8dda7 100644 --- a/bob/pad/face/database/celeb_a.py +++ b/bob/pad/face/database/celeb_a.py @@ -24,8 +24,9 @@ class CELEBAPadFile(PadFile): def __init__(self, client_id, path, attack_type=None, file_id=None): super(CELEBAPadFile, self).__init__(client_id, path, attack_type, file_id) - #========================================================================== - def load(self, directory=None, extension=None): + # ========================================================================== + def load(self, directory=None, extension=None, + frame_selector=bob.bio.video.FrameSelector(selection_style='all')): """ Overridden version of the load method defined in the ``PadFile``. @@ -39,6 +40,9 @@ class CELEBAPadFile(PadFile): Extension of the video files in the CELEBA database. Default: None + ``frame_selector`` : :any:`bob.bio.video.FrameSelector`, optional + Specifying the frames to be selected. + **Returns:** ``video_data`` : FrameContainer @@ -47,7 +51,6 @@ class CELEBAPadFile(PadFile): """ path = self.make_path(directory=directory, extension=extension) # path to the file - frame_selector = bob.bio.video.FrameSelector(selection_style = 'all') # this frame_selector will select all frames from the video file data = bob.io.base.load(path) data = np.expand_dims(data, axis=0) # upgrade to 4D (video) diff --git a/setup.py b/setup.py index 9f08a988..2ab5c0fe 100644 --- a/setup.py +++ b/setup.py @@ -109,6 +109,7 @@ setup( 'empty-preprocessor = bob.pad.face.config.preprocessor.filename:empty_preprocessor', # no preprocessing 'rgb-face-detect-dlib = bob.pad.face.config.preprocessor.video_face_crop:rgb_face_detector_dlib', # detect faces locally replacing database annotations 'rgb-face-detect-mtcnn = bob.pad.face.config.preprocessor.video_face_crop:rgb_face_detector_mtcnn', # detect faces locally replacing database annotations + 'bw-face-detect-mtcnn = bob.pad.face.config.preprocessor.video_face_crop:bw_face_detect_mtcnn', # detect faces locally, return BW image ], # registered extractors: -- GitLab