diff --git a/bob/bio/face/algorithm/GaborJet.py b/bob/bio/face/algorithm/GaborJet.py index 7f1079ad1c4df7f3835f62ef4142da05bb822e38..a878819f1f53f78cc60a8ba48bedde34a6a1dd59 100644 --- a/bob/bio/face/algorithm/GaborJet.py +++ b/bob/bio/face/algorithm/GaborJet.py @@ -9,7 +9,7 @@ import numpy import math from bob.bio.base.algorithm import Algorithm - +from bob.bio.face.extractor import GridGraph class GaborJet(Algorithm): """Computes a comparison of lists of Gabor jets using a similarity function of :py:class:`bob.ip.gabor.Similarity`. @@ -215,8 +215,8 @@ class GaborJet(Algorithm): model = [] for g in range(count): name = "Node-" + str(g + 1) - f.cd(name) - model.append(bob.ip.gabor.load_jets(f)) + f.cd(name) + model.append(GridGraph.serialize_jets(bob.ip.gabor.load_jets(f))) f.cd("..") return model diff --git a/bob/bio/face/extractor/GridGraph.py b/bob/bio/face/extractor/GridGraph.py index 70e3284e67e34a3ffc2ef7c990669aa85a99ffbe..89e8e5dc14b56cc9fc55b97ff8bf5b92c9df4118 100644 --- a/bob/bio/face/extractor/GridGraph.py +++ b/bob/bio/face/extractor/GridGraph.py @@ -264,7 +264,7 @@ class GridGraph(Extractor): feature : [:py:class:`bob.ip.gabor.Jet`] The list of Gabor jets read from file. """ - return bob.ip.gabor.load_jets(bob.io.base.HDF5File(feature_file)) + return self.__class__.serialize_jets(bob.ip.gabor.load_jets(bob.io.base.HDF5File(feature_file))) # re-define the train function to get it non-documented def train(*args, **kwargs): @@ -277,10 +277,22 @@ class GridGraph(Extractor): def __getstate__(self): d = dict(self.__dict__) - d.pop("gwt") + d.pop("gwt") d.pop("_aligned_graph") + if "_graph" in d: + d.pop("_graph") return d def __setstate__(self, d): self.__dict__ = d self._init_non_pickables() + + + @staticmethod + def serialize_jets(jets): + serialize_jets = [] + for jet in jets: + sj = bob.ip.gabor.Jet(jet.length) + sj.jet = jet.jet + serialize_jets.append(sj) + return serialize_jets diff --git a/bob/bio/face/test/test_picklability.py b/bob/bio/face/test/test_picklability.py index b383b89b817f26426d44adf30b5ff056a2a852d0..13a1d03fe72f36083396f84f97691b7ed428f9e7 100644 --- a/bob/bio/face/test/test_picklability.py +++ b/bob/bio/face/test/test_picklability.py @@ -1,6 +1,7 @@ import bob.bio.face import bob.bio.base from bob.pipelines.utils import assert_picklable +import numpy ### Preprocessors @@ -16,7 +17,7 @@ def test_face_crop(): color_channel="rgb", dtype="uint8", ) - assert_picklable(cropper) + assert assert_picklable(cropper) def test_face_detect(): @@ -26,31 +27,31 @@ def test_face_detect(): face_detect = bob.bio.face.preprocessor.FaceDetect( face_cropper="face-crop-eyes", use_flandmark=True ) - assert_picklable(face_detect) + assert assert_picklable(face_detect) def test_INormLBP(): face_crop = bob.bio.face.preprocessor.INormLBP(face_cropper="face-crop-eyes") - assert_picklable(face_crop) + assert assert_picklable(face_crop) def test_TanTriggs(): face_crop = bob.bio.face.preprocessor.TanTriggs(face_cropper="face-crop-eyes") - assert_picklable(face_crop) + assert assert_picklable(face_crop) def test_SQI(): face_crop = bob.bio.face.preprocessor.SelfQuotientImage( face_cropper="face-crop-eyes" ) - assert_picklable(face_crop) + assert assert_picklable(face_crop) def test_HistogramEqualization(): face_crop = bob.bio.face.preprocessor.HistogramEqualization( face_cropper="face-crop-eyes" ) - assert_picklable(face_crop) + assert assert_picklable(face_crop) ### Extractors @@ -61,16 +62,24 @@ def test_DCT(): assert_picklable(extractor) -def test_GridGraph(): +def test_GridGraph(): extractor = bob.bio.face.extractor.GridGraph(node_distance=24) - assert_picklable(extractor) + assert assert_picklable(extractor) + + fake_image = numpy.arange(64*80).reshape(64,80).astype("float") + extractor(fake_image) + assert assert_picklable(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_picklable(extractor) + assert assert_picklable(extractor) + + + def test_LGBPHS(): @@ -85,7 +94,7 @@ def test_LGBPHS(): sparse_histogram=True, ) - assert_picklable(extractor) + assert assert_picklable(extractor) ## Algorithms @@ -96,9 +105,9 @@ def test_GaborJet(): algorithm = bob.bio.face.algorithm.GaborJet( "PhaseDiffPlusCanberra", multiple_feature_scoring="average_model" ) - assert_picklable(algorithm) + assert assert_picklable(algorithm) def test_Histogram(): algorithm = bob.bio.face.algorithm.Histogram() - assert_picklable(algorithm) + assert assert_picklable(algorithm)