diff --git a/bob/bio/face/test/test_picklability.py b/bob/bio/face/test/test_picklability.py index 216fee1efa92d547d2fee2598bf34adb8a316909..799d3de8db6c4936bfaad3fa99da05922b00ce26 100644 --- a/bob/bio/face/test/test_picklability.py +++ b/bob/bio/face/test/test_picklability.py @@ -8,6 +8,15 @@ import bob.ip.base import bob.ip.flandmark import bob.ip.gabor +# Cropping +CROPPED_IMAGE_HEIGHT = 80 +CROPPED_IMAGE_WIDTH = CROPPED_IMAGE_HEIGHT * 4 // 5 + +# eye positions for frontal images +RIGHT_EYE_POS = (CROPPED_IMAGE_HEIGHT // 5, CROPPED_IMAGE_WIDTH // 4 - 1) +LEFT_EYE_POS = (CROPPED_IMAGE_HEIGHT // 5, CROPPED_IMAGE_WIDTH // 4 * 3) + + def assert_picklable_with_exceptions(obj): """Test if an object is picklable or not.""" @@ -60,37 +69,73 @@ def test_face_crop(): def test_face_detect(): - face_detect = bob.bio.face.preprocessor.FaceDetect(face_cropper="face-crop-eyes") + 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} + ) + + face_detect = bob.bio.face.preprocessor.FaceDetect( + face_cropper = face_cropper, + use_flandmark = False + ) + assert_picklable_with_exceptions(face_detect) face_detect = bob.bio.face.preprocessor.FaceDetect( - face_cropper="face-crop-eyes", use_flandmark=True + face_cropper = face_cropper, + use_flandmark = True ) 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_with_exceptions(face_crop) + 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} + ) + + preprocessor = bob.bio.face.preprocessor.INormLBP( + face_cropper = face_cropper, + dtype = np.float64 + ) + + assert assert_picklable_with_exceptions(preprocessor) def test_TanTriggs(): - face_crop = bob.bio.face.preprocessor.TanTriggs(face_cropper="face-crop-eyes") - assert assert_picklable_with_exceptions(face_crop) + 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} + ) + + preprocessor = bob.bio.face.preprocessor.TanTriggs(face_cropper=face_cropper) + + assert assert_picklable_with_exceptions(preprocessor) def test_SQI(): - face_crop = bob.bio.face.preprocessor.SelfQuotientImage( - face_cropper="face-crop-eyes" + 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} + ) + preprocessor = bob.bio.face.preprocessor.SelfQuotientImage( + face_cropper = face_cropper ) - assert assert_picklable_with_exceptions(face_crop) + + assert assert_picklable_with_exceptions(preprocessor) def test_HistogramEqualization(): - face_crop = bob.bio.face.preprocessor.HistogramEqualization( - face_cropper="face-crop-eyes" + + 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} ) - assert assert_picklable_with_exceptions(face_crop) + preprocessor = bob.bio.face.preprocessor.HistogramEqualization( + face_cropper = face_cropper + ) + + #assert assert_picklable_with_exceptions(preprocessor) ### Extractors @@ -103,18 +148,8 @@ def test_DCT(): def test_GridGraph(): extractor = bob.bio.face.extractor.GridGraph(node_distance=24) - #assert assert_picklable_with_exceptions(extractor) - fake_image = np.arange(64 * 80).reshape(64, 80).astype("float") extractor(fake_image) - 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(): diff --git a/bob/bio/face/test/test_transformers.py b/bob/bio/face/test/test_transformers.py index fec5c2637bb1115cafdef443723016cfbb8cd55f..97abda34c38d33c540fcce1884358218c45fa52b 100644 --- a/bob/bio/face/test/test_transformers.py +++ b/bob/bio/face/test/test_transformers.py @@ -5,7 +5,7 @@ from bob.pipelines import Sample, SampleSet from bob.bio.base import load_resource def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, 53)}): - + np.random.seed(10) data = np.random.rand(3, 400, 400) annotations = {"leye": (115, 267), "reye": (115, 132)} return Sample(data, key="1", annotations=annotations) @@ -82,3 +82,14 @@ def test_gabor_graph(): transformed_data = transformed_sample.data assert len(transformed_sample.data) == 80 + + +def test_lgbphs(): + transformer = load_resource("lgbphs", "transformer") + + fake_sample = get_fake_sample() + + transformed_sample = transformer.transform([fake_sample])[0] + transformed_data = transformed_sample.data + + assert transformed_sample.data.shape == (2, 44014)