Commit 7a8a04ba authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Add a command to finalize scores

parent a029591f
Pipeline #25360 passed with stage
in 14 minutes and 54 seconds
"""Finalizes the scores that are produced by
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
$ 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),
@click.option('-m', '--method', default='mean',
type=click.Choice(['mean', 'min', 'max']), show_default=True,
help='The method to use when finalizing the scores.')
def finalize_scores(scores, method, **kwargs):
"""Finalizes the scores given by
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.
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()
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:
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:
......@@ -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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment