Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.pad.base
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
bob
bob.pad.base
Commits
edf4910f
Commit
edf4910f
authored
6 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Fixes
#8
Algorithm.read_toscore_object should not exist
parent
5d9460a9
No related branches found
No related tags found
No related merge requests found
Pipeline
#26921
passed
6 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bob/pad/base/algorithm/Algorithm.py
+3
-22
3 additions, 22 deletions
bob/pad/base/algorithm/Algorithm.py
bob/pad/base/script/spoof.py
+1
-0
1 addition, 0 deletions
bob/pad/base/script/spoof.py
bob/pad/base/tools/scoring.py
+11
-6
11 additions, 6 deletions
bob/pad/base/tools/scoring.py
with
15 additions
and
28 deletions
bob/pad/base/algorithm/Algorithm.py
+
3
−
22
View file @
edf4910f
...
...
@@ -85,7 +85,9 @@ class Algorithm(object):
**Parameters:**
toscore : object
The object to compute the score for.
The object to compute the score for. This will be the output of
extractor if performs_projection is False, otherwise this will be the
output of project method of the algorithm.
**Returns:**
...
...
@@ -159,27 +161,6 @@ class Algorithm(object):
"""
return
utils
.
load
(
feature_file
)
def
read_toscore_object
(
self
,
toscore_object_file
):
"""
read_toscore_object(toscore_object_file) -> toscore_object
Reads the toscore_object feature from a file.
By default, the toscore_object feature is identical to the projected feature.
Hence, this base class implementation simply calls :py:meth:`read_feature`.
If your algorithm requires different behavior, please overwrite this function.
**Parameters:**
toscore_object_file : str or :py:class:`bob.io.base.HDF5File`
The file open for reading, or the file name to read from.
**Returns:**
toscore_object : object
The toscore_object that was read from file.
"""
return
self
.
read_feature
(
toscore_object_file
)
def
train_projector
(
self
,
training_features
,
projector_file
):
"""
This function can be overwritten to train the feature projector.
If you do this, please also register the function by calling this base class constructor
...
...
This diff is collapsed.
Click to expand it.
bob/pad/base/script/spoof.py
+
1
−
0
View file @
edf4910f
...
...
@@ -202,6 +202,7 @@ def execute(args):
elif
args
.
sub_task
==
'
compute-scores
'
:
tools
.
compute_scores
(
args
.
algorithm
,
args
.
extractor
,
groups
=
[
args
.
group
],
allow_missing_files
=
args
.
allow_missing_files
,
force
=
args
.
force
,
...
...
This diff is collapsed.
Click to expand it.
bob/pad/base/tools/scoring.py
+
11
−
6
View file @
edf4910f
...
...
@@ -23,7 +23,7 @@ from .FileSelector import FileSelector
from
bob.bio.base
import
utils
def
_compute_scores
(
algorithm
,
toscore_objects
,
allow_missing_files
):
def
_compute_scores
(
algorithm
,
extractor
,
toscore_objects
,
allow_missing_files
):
"""
Compute scores for the given list of objects using provided algorithm.
"""
# the scores to be computed
...
...
@@ -37,7 +37,10 @@ def _compute_scores(algorithm, toscore_objects, allow_missing_files):
scores
.
insert
(
i
,
[
numpy
.
nan
])
continue
# read toscore
toscore
=
algorithm
.
read_toscore_object
(
toscore_element
)
if
algorithm
.
performs_projection
:
toscore
=
algorithm
.
read_feature
(
toscore_element
)
else
:
toscore
=
extractor
.
read_feature
(
toscore_element
)
# compute score
if
isinstance
(
toscore
,
list
)
or
isinstance
(
toscore
[
0
],
numpy
.
ndarray
):
scores
.
insert
(
i
,
algorithm
.
score_for_multiple_projections
(
toscore
))
...
...
@@ -120,7 +123,7 @@ def _save_scores(score_file, scores, toscore_objects, write_compressed=False):
_close_written
(
score_file
,
f
,
write_compressed
)
def
_scores_all
(
algorithm
,
group
,
force
,
allow_missing_files
=
False
,
write_compressed
=
False
):
def
_scores_all
(
algorithm
,
extractor
,
group
,
force
,
allow_missing_files
=
False
,
write_compressed
=
False
):
"""
Computes scores for all (real, attack) files in a given group using the provided algorithm.
"""
# the file selector object
fs
=
FileSelector
.
instance
()
...
...
@@ -148,7 +151,7 @@ def _scores_all(algorithm, group, force, allow_missing_files=False, write_compre
# get the attack files
current_files
=
fs
.
get_paths
(
current_objects
,
'
projected
'
if
algorithm
.
performs_projection
else
'
extracted
'
)
# compute scores for the list of File objects
cur_scores
=
_compute_scores
(
algorithm
,
current_files
,
allow_missing_files
)
cur_scores
=
_compute_scores
(
algorithm
,
extractor
,
current_files
,
allow_missing_files
)
total_scores
+=
cur_scores
# Save scores to text file
_save_scores
(
score_file
,
cur_scores
,
current_objects
,
write_compressed
)
...
...
@@ -164,7 +167,7 @@ def _scores_all(algorithm, group, force, allow_missing_files=False, write_compre
current_toscore_objects
[
0
]
+
current_toscore_objects
[
1
],
write_compressed
)
def
compute_scores
(
algorithm
,
force
=
False
,
groups
=
[
'
dev
'
,
'
eval
'
],
allow_missing_files
=
False
,
write_compressed
=
False
):
def
compute_scores
(
algorithm
,
extractor
,
force
=
False
,
groups
=
[
'
dev
'
,
'
eval
'
],
allow_missing_files
=
False
,
write_compressed
=
False
):
"""
Computes the scores for the given groups.
This function computes all scores for the experiment and writes them to score files.
...
...
@@ -175,6 +178,8 @@ def compute_scores(algorithm, force=False, groups=['dev', 'eval'], allow_missing
algorithm : py:class:`bob.bio.base.algorithm.Algorithm` or derived
The algorithm, used for enrolling model and writing them to file.
extractor : py:class:`bob.bio.base.extractor.Extractor` or derived
force : bool
If given, files are regenerated, even if they already exist.
...
...
@@ -192,4 +197,4 @@ def compute_scores(algorithm, force=False, groups=['dev', 'eval'], allow_missing
algorithm
.
load_projector
(
fs
.
projector_file
)
for
group
in
groups
:
_scores_all
(
algorithm
,
group
,
force
,
allow_missing_files
,
write_compressed
)
_scores_all
(
algorithm
,
extractor
,
group
,
force
,
allow_missing_files
,
write_compressed
)
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