Skip to content
Snippets Groups Projects
Commit 09ba5486 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

TEsted LGBPHS transformer

parent 27c75ad2
Branches
Tags v2.2.6
2 merge requests!66Adding some baselines as transformers,!64Dask pipelines
...@@ -8,6 +8,15 @@ import bob.ip.base ...@@ -8,6 +8,15 @@ import bob.ip.base
import bob.ip.flandmark import bob.ip.flandmark
import bob.ip.gabor 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): def assert_picklable_with_exceptions(obj):
"""Test if an object is picklable or not.""" """Test if an object is picklable or not."""
...@@ -60,37 +69,73 @@ def test_face_crop(): ...@@ -60,37 +69,73 @@ def test_face_crop():
def test_face_detect(): 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) assert_picklable_with_exceptions(face_detect)
face_detect = bob.bio.face.preprocessor.FaceDetect( 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) assert assert_picklable_with_exceptions(face_detect)
def test_INormLBP(): def test_INormLBP():
face_crop = bob.bio.face.preprocessor.INormLBP(face_cropper="face-crop-eyes") face_cropper = bob.bio.face.preprocessor.FaceCrop(
assert assert_picklable_with_exceptions(face_crop) 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(): def test_TanTriggs():
face_crop = bob.bio.face.preprocessor.TanTriggs(face_cropper="face-crop-eyes") face_cropper = bob.bio.face.preprocessor.FaceCrop(
assert assert_picklable_with_exceptions(face_crop) 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(): def test_SQI():
face_crop = bob.bio.face.preprocessor.SelfQuotientImage( face_cropper = bob.bio.face.preprocessor.FaceCrop(
face_cropper="face-crop-eyes" 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(): 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 ### Extractors
...@@ -103,18 +148,8 @@ def test_DCT(): ...@@ -103,18 +148,8 @@ def test_DCT():
def test_GridGraph(): def test_GridGraph():
extractor = bob.bio.face.extractor.GridGraph(node_distance=24) 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") fake_image = np.arange(64 * 80).reshape(64, 80).astype("float")
extractor(fake_image) 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(): def test_LGBPHS():
......
...@@ -5,7 +5,7 @@ from bob.pipelines import Sample, SampleSet ...@@ -5,7 +5,7 @@ from bob.pipelines import Sample, SampleSet
from bob.bio.base import load_resource from bob.bio.base import load_resource
def get_fake_sample(face_size=(160, 160), eyes={"leye": (46, 107), "reye": (46, 53)}): 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) data = np.random.rand(3, 400, 400)
annotations = {"leye": (115, 267), "reye": (115, 132)} annotations = {"leye": (115, 267), "reye": (115, 132)}
return Sample(data, key="1", annotations=annotations) return Sample(data, key="1", annotations=annotations)
...@@ -82,3 +82,14 @@ def test_gabor_graph(): ...@@ -82,3 +82,14 @@ def test_gabor_graph():
transformed_data = transformed_sample.data transformed_data = transformed_sample.data
assert len(transformed_sample.data) == 80 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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment