Commit 51c0f8f4 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

Change option titles->legends; fix bug: incorrect reading of input files

parent cf03a121
Pipeline #19601 canceled with stage
in 49 seconds
......@@ -16,7 +16,7 @@ from bob.extension.scripts.click_helper import (verbosity_option,
@common_options.criterion_option()
@common_options.thresholds_option()
@common_options.far_option()
@common_options.titles_option()
@common_options.legends_option()
@open_file_mode_option()
@verbosity_option()
@click.pass_context
......@@ -43,7 +43,7 @@ def metrics(ctx, scores, evaluation, **kwargs):
@click.command()
@common_options.scores_argument(nargs=-1)
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.sep_dev_eval_option()
@common_options.output_plot_file_option(default_out='roc.pdf')
@common_options.eval_option()
......@@ -83,7 +83,7 @@ def roc(ctx, scores, evaluation, **kwargs):
@common_options.scores_argument(nargs=-1)
@common_options.output_plot_file_option(default_out='det.pdf')
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.sep_dev_eval_option()
@common_options.eval_option()
@common_options.axes_val_option(dflt=[0.01, 95, 0.01, 95])
......@@ -121,7 +121,7 @@ def det(ctx, scores, evaluation, **kwargs):
@common_options.scores_argument(min_arg=1, force_eval=True, nargs=-1)
@common_options.output_plot_file_option(default_out='epc.pdf')
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.points_curve_option()
@common_options.const_layout_option()
@common_options.x_label_option()
......@@ -158,7 +158,7 @@ def epc(ctx, scores, **kwargs):
@common_options.show_dev_option()
@common_options.print_filenames_option()
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.figsize_option()
@common_options.style_option()
@verbosity_option()
......@@ -189,7 +189,7 @@ def hist(ctx, scores, evaluation, **kwargs):
@click.command()
@common_options.scores_argument(nargs=-1)
@common_options.titles_option()
@common_options.legends_option()
@common_options.sep_dev_eval_option()
@common_options.table_option()
@common_options.eval_option()
......
......@@ -288,7 +288,7 @@ def figsize_option(**kwargs):
plt.rcParams['figure.figsize'] = ctx.meta['figsize']
return value
return click.option(
'--figsize', help='If given, will run '
'--figsize', default='4,3', help='If given, will run '
'``plt.rcParams[\'figure.figsize\']=figsize)``. Example: --fig-size 4,6',
callback=callback, **kwargs)(func)
return custom_figsize_option
......@@ -341,20 +341,20 @@ def marker_style_option(**kwargs):
callback=callback, **kwargs)(func)
return custom_marker_style_option
def titles_option(**kwargs):
'''Get the titles option for the different systems'''
def custom_titles_option(func):
def legends_option(**kwargs):
'''Get the legends option for the different systems'''
def custom_legends_option(func):
def callback(ctx, param, value):
if value is not None:
value = value.split(',')
ctx.meta['titles'] = value
ctx.meta['legends'] = value
return value
return click.option(
'-ts', '--titles', type=click.STRING, default=None,
'-ls', '--legends', type=click.STRING, default=None,
help='The title for each system comma separated. '
'Example: --titles ISV,CNN',
'Example: --legends ISV,CNN',
callback=callback, **kwargs)(func)
return custom_titles_option
return custom_legends_option
def title_option(**kwargs):
'''Get the title option for the different systems'''
......
......@@ -56,7 +56,7 @@ class MeasureBase(object):
self._min_arg = 1 if 'min_arg' not in ctx.meta else ctx.meta['min_arg']
self._ctx = ctx
self.func_load = func_load
self._titles = None if 'titles' not in ctx.meta else ctx.meta['titles']
self._legends = None if 'legends' not in ctx.meta else ctx.meta['legends']
self._eval = evaluation
self._min_arg = 1 if 'min_arg' not in ctx.meta else ctx.meta['min_arg']
if len(scores) < 1 or len(scores) % self._min_arg != 0:
......@@ -64,8 +64,8 @@ class MeasureBase(object):
'Number of argument must be a non-zero multiple of %d' % self._min_arg
)
self.n_systems = int(len(scores) / self._min_arg)
if self._titles is not None and len(self._titles) != self.n_systems:
raise click.BadParameter("Number of titles must be equal to the "
if self._legends is not None and len(self._legends) != self.n_systems:
raise click.BadParameter("Number of legends must be equal to the "
"number of systems")
def run(self):
......@@ -85,7 +85,7 @@ class MeasureBase(object):
# each system
for idx in range(self.n_systems):
input_scores, input_names = self._load_files(
self._scores[idx:(idx + self._min_arg)]
self._scores[idx * self._min_arg:(idx + 1) * self._min_arg]
)
self.compute(idx, input_scores, input_names)
#setup final configuration, plotting properties, ...
......@@ -188,7 +188,7 @@ class Metrics(MeasureBase):
threshold = utils.get_thres(self._criterion, dev_neg, dev_pos, self._far) \
if self._thres is None else self._thres[idx]
title = self._titles[idx] if self._titles is not None else None
title = self._legends[idx] if self._legends is not None else None
if self._thres is None:
far_str = ''
if self._criterion == 'far' and self._far is not None:
......@@ -364,8 +364,8 @@ class PlotBase(MeasureBase):
#common protected functions
def _label(self, base, name, idx):
if self._titles is not None and len(self._titles) > idx:
return self._titles[idx]
if self._legends is not None and len(self._legends) > idx:
return self._legends[idx]
if self.n_systems > 1:
return base + (" %d (%s)" % (idx + 1, name))
return base + (" (%s)" % name)
......@@ -584,7 +584,7 @@ class Hist(PlotBase):
self._pdf_page.savefig(fig)
def _get_title(self, idx, dev_file, eval_file):
title = self._titles[idx] if self._titles is not None else None
title = self._legends[idx] if self._legends is not None else None
if title is None:
title = self._title_base if not self._print_fn else \
('%s \n (%s)' % (
......
......@@ -30,7 +30,7 @@ def test_metrics():
assert result.exit_code == 0
with runner.isolated_filesystem():
result = runner.invoke(
commands.metrics, ['-l', 'tmp', dev1, test1, dev2, test2, '-ts',
commands.metrics, ['-l', 'tmp', dev1, test1, dev2, test2, '-ls',
'A,B']
)
assert result.exit_code == 0, (result.exit_code, result.output)
......@@ -63,7 +63,7 @@ def test_roc():
with runner.isolated_filesystem():
result = runner.invoke(commands.roc, ['--output',
'test.pdf', '--titles', 'A,B',
'test.pdf', '--legends', 'A,B',
dev1, test1, dev2, test2])
if result.output:
click.echo(result.output)
......@@ -83,7 +83,7 @@ def test_det():
test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
with runner.isolated_filesystem():
result = runner.invoke(commands.det, ['--split', '--output',
'test.pdf', '--titles', 'A,B',
'test.pdf', '--legends', 'A,B',
dev1, test1, dev2, test2])
if result.output:
click.echo(result.output)
......@@ -111,7 +111,7 @@ def test_epc():
test2 = bob.io.base.test_utils.datafile('test-2.txt', 'bob.measure')
with runner.isolated_filesystem():
result = runner.invoke(commands.epc, ['--output', 'test.pdf',
'--titles', 'A,B',
'--legends', 'A,B',
dev1, test1, dev2, test2])
if result.output:
click.echo(result.output)
......
Markdown is supported
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