Skip to content
Snippets Groups Projects
Commit 35c8f87c authored by Manuel Günther's avatar Manuel Günther
Browse files

Use numpy.spatial.distance.euclidean instead of lambda function.

parent 9e0930f1
Branches
Tags
No related merge requests found
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
import bob import bob
import xbob.db.atnt import xbob.db.atnt
import os, sys import os, sys
import numpy, numpy.linalg import numpy, scipy.spatial
from matplotlib import pyplot from matplotlib import pyplot
# This is the base directory where by default the AT&T images are found. You can # This is the base directory where by default the AT&T images are found. You can
...@@ -78,6 +78,8 @@ def extract_feature(image, pca_machine): ...@@ -78,6 +78,8 @@ def extract_feature(image, pca_machine):
return projected_feature return projected_feature
DISTANCE_FUNCTION = scipy.spatial.distance.euclidean
def main(): def main():
"""This function will perform an eigenface test on the AT&T database""" """This function will perform an eigenface test on the AT&T database"""
...@@ -130,13 +132,12 @@ def main(): ...@@ -130,13 +132,12 @@ def main():
negative_scores = [] negative_scores = []
print "Computing scores" print "Computing scores"
distance_function = (lambda x,y: numpy.linalg.norm(x - y))
# iterate through models and probes and compute scores # iterate through models and probes and compute scores
for model_key, model_feature in model_features.iteritems(): for model_key, model_feature in model_features.iteritems():
for probe_key, probe_feature in probe_features.iteritems(): for probe_key, probe_feature in probe_features.iteritems():
# compute score as the negative Euclidean distance # compute score as the negative Euclidean distance
score = - distance_function(model_feature, probe_feature) score = - DISTANCE_FUNCTION(model_feature, probe_feature)
# check if this is a positive score # check if this is a positive score
if atnt_db.get_client_id_from_file_id(model_key) == atnt_db.get_client_id_from_file_id(probe_key): if atnt_db.get_client_id_from_file_id(model_key) == atnt_db.get_client_id_from_file_id(probe_key):
......
...@@ -55,7 +55,7 @@ class FaceVerifyExampleTest(unittest.TestCase): ...@@ -55,7 +55,7 @@ class FaceVerifyExampleTest(unittest.TestCase):
def test01_eigenface(self): def test01_eigenface(self):
# test the eigenface algorithm # test the eigenface algorithm
try: try:
from faceverify.eigenface import load_images, train, extract_feature from faceverify.eigenface import load_images, train, extract_feature, DISTANCE_FUNCTION
except ImportError as e: except ImportError as e:
raise SkipTest("Skipping the tests since importing from faceverify.eigenface raised exception '%s'"%e) raise SkipTest("Skipping the tests since importing from faceverify.eigenface raised exception '%s'"%e)
...@@ -92,7 +92,7 @@ class FaceVerifyExampleTest(unittest.TestCase): ...@@ -92,7 +92,7 @@ class FaceVerifyExampleTest(unittest.TestCase):
self.assertTrue(numpy.allclose(probe_ref, probe)) self.assertTrue(numpy.allclose(probe_ref, probe))
# compute score # compute score
score = numpy.linalg.norm(model - probe) score = DISTANCE_FUNCTION(model, probe)
self.assertAlmostEqual(score, 3498.308154114) self.assertAlmostEqual(score, 3498.308154114)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment