Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
bob.pad.base
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bob
bob.pad.base
Commits
7a8a04ba
Commit
7a8a04ba
authored
Dec 11, 2018
by
Amir MOHAMMADI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a command to finalize scores
parent
a029591f
Pipeline
#25360
passed with stage
in 14 minutes and 54 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
bob/pad/base/script/finalize_scores.py
bob/pad/base/script/finalize_scores.py
+60
-0
setup.py
setup.py
+1
-0
No files found.
bob/pad/base/script/finalize_scores.py
0 → 100644
View file @
7a8a04ba
"""Finalizes the scores that are produced by spoof.py
"""
import
click
import
numpy
import
logging
from
bob.extension.scripts.click_helper
import
(
verbosity_option
,
log_parameters
)
logger
=
logging
.
getLogger
(
__name__
)
@
click
.
command
(
name
=
'finalize-scores'
,
epilog
=
'''
\
b
Examples:
$ bin/bob pad finalize_scores /path/to/scores-dev
$ bin/bob pad finalize_scores /path/to/scores-{dev,eval}
'''
)
@
click
.
argument
(
'scores'
,
type
=
click
.
Path
(
exists
=
True
,
dir_okay
=
False
),
nargs
=-
1
)
@
click
.
option
(
'-m'
,
'--method'
,
default
=
'mean'
,
type
=
click
.
Choice
([
'mean'
,
'min'
,
'max'
]),
show_default
=
True
,
help
=
'The method to use when finalizing the scores.'
)
@
verbosity_option
()
def
finalize_scores
(
scores
,
method
,
**
kwargs
):
"""Finalizes the scores given by spoof.py
When using bob.pad.base, Algorithms can produce several score values for
each unique sample. You can use this script to average (or min/max) these
scores to have one final score per sample.
The conversion is done in-place. The order of scores will change.
"""
log_parameters
(
logger
)
mean
=
{
'mean'
:
numpy
.
nanmean
,
'max'
:
numpy
.
nanmax
,
'min'
:
numpy
.
nanmin
}[
method
]
for
path
in
scores
:
new_lines
=
[]
with
open
(
path
)
as
f
:
old_lines
=
f
.
readlines
()
old_lines
.
sort
()
for
i
,
line
in
enumerate
(
old_lines
):
uniq
,
s
=
line
.
strip
().
rsplit
(
maxsplit
=
1
)
s
=
float
(
s
)
if
i
==
0
:
last_line
=
uniq
last_scores
=
[]
if
uniq
==
last_line
:
last_scores
.
append
(
s
)
else
:
new_lines
.
append
(
'{} {}
\
n
'
.
format
(
last_line
,
mean
(
last_scores
)))
last_scores
=
[
s
]
last_line
=
uniq
else
:
# this else is for the for loop
new_lines
.
append
(
'{} {}
\
n
'
.
format
(
last_line
,
mean
(
last_scores
)))
with
open
(
path
,
'w'
)
as
f
:
f
.
writelines
(
new_lines
)
setup.py
View file @
7a8a04ba
...
...
@@ -148,6 +148,7 @@ setup(
'gen = bob.pad.base.script.pad_commands:gen'
,
'evaluate = bob.pad.base.script.pad_commands:evaluate'
,
'cross = bob.pad.base.script.cross:cross'
,
'finalize-scores = bob.pad.base.script.finalize_scores:finalize_scores'
,
],
# bob vuln scripts
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment