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
7a8a04ba
Commit
7a8a04ba
authored
6 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Add a command to finalize scores
parent
a029591f
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!53
Cross database testing evaluation
Pipeline
#25360
passed
6 years ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bob/pad/base/script/finalize_scores.py
+60
-0
60 additions, 0 deletions
bob/pad/base/script/finalize_scores.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
61 additions
and
0 deletions
bob/pad/base/script/finalize_scores.py
0 → 100644
+
60
−
0
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
)
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
7a8a04ba
...
@@ -148,6 +148,7 @@ setup(
...
@@ -148,6 +148,7 @@ setup(
'
gen = bob.pad.base.script.pad_commands:gen
'
,
'
gen = bob.pad.base.script.pad_commands:gen
'
,
'
evaluate = bob.pad.base.script.pad_commands:evaluate
'
,
'
evaluate = bob.pad.base.script.pad_commands:evaluate
'
,
'
cross = bob.pad.base.script.cross:cross
'
,
'
cross = bob.pad.base.script.cross:cross
'
,
'
finalize-scores = bob.pad.base.script.finalize_scores:finalize_scores
'
,
],
],
# bob vuln scripts
# bob vuln scripts
...
...
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