Commit e9e7bbb7 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira

Serialization of bob.ip.gabor.Jet

parent 34a6ea0a
Pipeline #39222 failed with stage
in 13 minutes and 17 seconds
......@@ -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
......
......@@ -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
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)
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