Commit 09ba5486 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

TEsted LGBPHS transformer

parent 27c75ad2
......@@ -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():
......
......@@ -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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment