Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.example.faceverify
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.example.faceverify
Commits
35c8f87c
Commit
35c8f87c
authored
11 years ago
by
Manuel Günther
Browse files
Options
Downloads
Patches
Plain Diff
Use numpy.spatial.distance.euclidean instead of lambda function.
parent
9e0930f1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
faceverify/eigenface.py
+4
-3
4 additions, 3 deletions
faceverify/eigenface.py
faceverify/tests/__init__.py
+2
-2
2 additions, 2 deletions
faceverify/tests/__init__.py
with
6 additions
and
5 deletions
faceverify/eigenface.py
+
4
−
3
View file @
35c8f87c
...
@@ -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
.
lin
al
g
import
numpy
,
scipy
.
spati
al
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
):
...
...
This diff is collapsed.
Click to expand it.
faceverify/tests/__init__.py
+
2
−
2
View file @
35c8f87c
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment