Commit 3defd9c3 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Improvements on the vuln epsc command

parent 99d3e0b1
Pipeline #21581 passed with stage
in 36 minutes and 51 seconds
......@@ -2,6 +2,7 @@
"""
import os
import logging
import numpy
import click
from click.types import FLOAT
......@@ -14,6 +15,7 @@ from bob.io.base import create_directories_safe
from bob.bio.base.score import load
from . import vuln_figure as figure
LOGGER = logging.getLogger(__name__)
NUM_GENUINE_ACCESS = 5000
NUM_ZEIMPOSTORS = 5000
NUM_PA = 5000
......@@ -236,16 +238,17 @@ def epc(ctx, scores, **kwargs):
@common_options.const_layout_option()
@common_options.x_label_option()
@common_options.y_label_option()
@common_options.figsize_option(dflt=None)
@common_options.figsize_option(dflt='5,3')
@common_options.style_option()
@common_options.bool_option(
'wer', 'w', 'Whether to plot the WER related lines or not.', True
)
@common_options.bool_option(
'three-d', 'D', 'If true, generate 3D plots', False
'three-d', 'D', 'If true, generate 3D plots. You need to turn off '
'wer or iapmr when using this option.', False
)
@common_options.bool_option(
'iapmr', 'I', 'Whether to plot the IAPMR related lines or not.', False
'iapmr', 'I', 'Whether to plot the IAPMR related lines or not.', True
)
@click.option('-c', '--criteria', default="eer", show_default=True,
help='Criteria for threshold selection',
......@@ -286,7 +289,8 @@ def epsc(ctx, scores, criteria, var_param, three_d, sampling,
fixed_params = ctx.meta.get('fixed_params', [0.5])
if three_d:
if (ctx.meta['wer'] and ctx.meta['iapmr']):
raise click.BadParameter('Cannot plot both WER and IAPMR in 3D')
LOGGER.info('Cannot plot both WER and IAPMR in 3D. Will turn IAPMR off.')
ctx.meta['iapmr'] = False
ctx.meta['sampling'] = sampling
process = figure.Epsc3D(
ctx, scores, True, load.split,
......
......@@ -246,8 +246,11 @@ class Epsc(VulnPlot):
spoof_eval_pos = input_scores[3][1]
merge_sys = (self._fixed_params is None or
len(self._fixed_params) == 1) and self.n_systems > 1
legend = self._legends[idx] if self._legends is not None and \
idx < len(self._legends) else 'Sys%d' % (idx + 1)
legend = ''
if self._legends is not None and idx < len(self._legends):
legend = self._legends[idx]
elif self.n_systems > 1:
legend = 'Sys%d' % (idx + 1)
n_col = 1 if self._iapmr else 0
n_col += 1 if self._wer else 0
......@@ -293,13 +296,13 @@ class Epsc(VulnPlot):
mpl.sca(self._axis1)
# between the negatives (impostors and Presentation attacks)
base = r"(%s) " % legend
base = r"(%s) " % legend if legend.strip() else ""
if self._wer:
set_title = self._titles[idx] if self._titles is not None and \
len(self._titles) > idx else None
len(self._titles) > idx else None
display = set_title.replace(' ', '') if set_title is not None\
else True
wer_title = set_title or "WER"
else True
wer_title = set_title or ""
if display:
mpl.title(wer_title)
if self._var_param == 'omega':
......@@ -319,11 +322,11 @@ class Epsc(VulnPlot):
if self._iapmr:
mpl.sca(self._axis2)
set_title = self._titles[idx + self.n_systems] \
if self._titles is not None and \
len(self._titles) > self.n_systems + idx else None
if self._titles is not None and \
len(self._titles) > self.n_systems + idx else None
display = set_title.replace(' ', '') if set_title is not None\
else True
iapmr_title = set_title or "IAPMR"
else True
iapmr_title = set_title or ""
if display:
mpl.title(iapmr_title)
if self._var_param == 'omega':
......@@ -336,8 +339,8 @@ class Epsc(VulnPlot):
else:
label = r"%s $\omega=%.1f$" % (base, fp)
mpl.plot(
beta, 100. * errors[2].flatten(), color=self._colors[pi],
linestyle='-', label=label
beta, 100. * errors[2].flatten(), linestyle='-',
color=self._colors[pi], label=label
)
mpl.xlabel(self._x_label or r"Weight $\beta$")
......@@ -345,7 +348,6 @@ class Epsc(VulnPlot):
self._axis2.set_xticklabels(self._axis2.get_xticks())
self._axis2.set_yticklabels(self._axis2.get_yticks())
self._axis1.set_xticklabels(self._axis1.get_xticks())
self._axis1.set_yticklabels(self._axis1.get_yticks())
mpl.xticks(rotation=self._x_rotation)
......@@ -354,8 +356,8 @@ class Epsc(VulnPlot):
# all plots share same legends
lines, labels = self._axis1.get_legend_handles_labels()
mpl.gcf().legend(
lines, labels, loc=self._legend_loc, fancybox=True,
framealpha=0.5, ncol=self._nlegends, bbox_to_anchor=(0.5, 1.12)
lines, labels, loc=self._legend_loc, fancybox=True, mode="expand",
framealpha=0.5, ncol=self._nlegends, bbox_to_anchor=(0., 1.12, 1., .102)
)
mpl.tight_layout()
self._pdf_page.savefig(bbox_inches='tight')
......
......@@ -13,7 +13,7 @@ def test_det_pad():
result = runner.invoke(pad_commands.det, ['-e', '--output',
'DET.pdf',
licit_dev, licit_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_det_vuln():
......@@ -32,7 +32,7 @@ def test_det_vuln():
'DET.pdf',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_fmr_iapmr_vuln():
......@@ -50,13 +50,13 @@ def test_fmr_iapmr_vuln():
'--output', 'FMRIAPMR.pdf', licit_dev, licit_test, spoof_dev,
spoof_test
])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
result = runner.invoke(vuln_commands.fmr_iapmr, [
'--output', 'FMRIAPMR.pdf', licit_dev, licit_test, spoof_dev,
spoof_test, '-G', '-L', '1e-7,1,0,1'
])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_hist_pad():
......@@ -71,7 +71,7 @@ def test_hist_pad():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(pad_commands.hist, [licit_dev])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
with runner.isolated_filesystem():
result = runner.invoke(pad_commands.hist, ['--criterion', 'min-hter',
......@@ -79,7 +79,7 @@ def test_hist_pad():
'HISTO.pdf', '-b',
'30,20',
licit_dev, spoof_dev])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
with runner.isolated_filesystem():
result = runner.invoke(pad_commands.hist, ['-e', '--criterion', 'eer',
......@@ -87,7 +87,7 @@ def test_hist_pad():
'HISTO.pdf', '-b', '30',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_hist_vuln():
......@@ -105,7 +105,7 @@ def test_hist_vuln():
['--criterion', 'eer', '--output',
'HISTO.pdf', '-b', '30', '-ts', 'A,B',
licit_dev, licit_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
with runner.isolated_filesystem():
result = runner.invoke(vuln_commands.hist,
......@@ -113,7 +113,7 @@ def test_hist_vuln():
'HISTO.pdf', '-b', '2,20,30', '-e',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_metrics_pad():
......@@ -127,7 +127,7 @@ def test_metrics_pad():
pad_commands.metrics,
['-e', licit_dev, licit_test]
)
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_epc_vuln():
......@@ -145,13 +145,13 @@ def test_epc_vuln():
['--output', 'epc.pdf',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
result = runner.invoke(vuln_commands.epc,
['--output', 'epc.pdf', '-I',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_epsc_vuln():
......@@ -176,7 +176,7 @@ def test_epsc_vuln():
'-fp', '0.1,0.3',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_epsc_3D_vuln():
licit_dev = pkg_resources.resource_filename('bob.pad.base.test',
......@@ -193,14 +193,14 @@ def test_epsc_3D_vuln():
['--output', 'epsc.pdf', '-D',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
result = runner.invoke(vuln_commands.epsc,
['--output', 'epsc.pdf', '-D',
'-I', '--no-wer',
licit_dev, licit_test,
spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
def test_evaluate_pad():
......@@ -216,4 +216,4 @@ def test_evaluate_pad():
with runner.isolated_filesystem():
result = runner.invoke(pad_commands.evaluate,
[licit_dev, licit_test, spoof_dev, spoof_test])
assert result.exit_code == 0, (result.exit_code, result.output)
assert result.exit_code == 0, (result.exit_code, result.output, result.exception)
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