pad_figure.py 1.76 KB
Newer Older
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
1 2 3 4 5 6 7 8 9
'''Runs error analysis on score sets, outputs metrics and plots'''

import bob.measure.script.figure as measure_figure
import bob.bio.base.script.figure as bio_figure
from .error_utils import calc_threshold

ALL_CRITERIA = ('bpcer20', 'eer', 'min-hter')


10
class Metrics(bio_figure.Metrics):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
11 12
    '''Compute metrics from score files'''

13
    def __init__(self, ctx, scores, evaluation, func_load,
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
14
                names=('FtA', 'APCER', 'BPCER', 'FAR', 'FRR', 'HTER')):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
15
        super(Metrics, self).__init__(
16 17
            ctx, scores, evaluation, func_load, names
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

    def get_thres(self, criterion, dev_neg, dev_pos, far):
        if self._criterion == 'bpcer20':
            return calc_threshold('bpcer20', dev_neg, dev_pos)
        else:
            return super(Metrics, self).get_thres(
                criterion, dev_neg, dev_pos, far)


class Roc(bio_figure.Roc):
    '''ROC for PAD'''

    def __init__(self, ctx, scores, evaluation, func_load):
        super(Roc, self).__init__(ctx, scores, evaluation, func_load)
        self._x_label = ctx.meta.get('x_label') or 'APCER'
        self._y_label = ctx.meta.get('y_label') or '1 - BPCER'


class Det(bio_figure.Det):
    def __init__(self, ctx, scores, evaluation, func_load):
        super(Det, self).__init__(ctx, scores, evaluation, func_load)
        self._x_label = ctx.meta.get('x_label') or 'APCER (%)'
        self._y_label = ctx.meta.get('y_label') or 'BPCER (%)'


class Hist(measure_figure.Hist):
    ''' Histograms for PAD '''

    def _setup_hist(self, neg, pos):
        self._title_base = 'PAD'
        self._density_hist(
49
            pos[0], n=0, label='Bona-fide', color='C1'
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
50 51 52 53 54
        )
        self._density_hist(
            neg[0], n=1, label='Presentation attack', alpha=0.4, color='C7',
            hatch='\\\\'
        )