pad_figure.py 2.43 KB
Newer Older
1

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
2 3 4 5 6 7 8 9 10
'''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')


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

14
    def __init__(self, ctx, scores, evaluation, func_load,
Theophile GENTILHOMME's avatar
Theophile GENTILHOMME committed
15
                names=('FtA', 'APCER', 'BPCER', 'FAR', 'FRR', 'HTER')):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
16
        super(Metrics, self).__init__(
17 18
            ctx, scores, evaluation, func_load, names
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
19 20 21 22 23 24

    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(
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
                criterion, dev_neg, dev_pos, far)


class MultiMetrics(measure_figure.MultiMetrics):
    '''Compute metrics from score files'''

    def __init__(self, ctx, scores, evaluation, func_load):
        super(MultiMetrics, self).__init__(
            ctx, scores, evaluation, func_load,
            names=('FtA', 'APCER', 'BPCER', 'FAR', 'FRR', 'ACER'))

    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(MultiMetrics, self).get_thres(
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
41 42 43 44 45 46 47 48 49
                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'
50 51 52
        default_y_label = '1-BPCER' if self._semilogx \
            else 'BPCER'
        self._y_label = ctx.meta.get('y_label') or default_y_label
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67


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(
68
            pos[0], n=0, label='Bona-fide', color='C1'
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
69 70 71 72 73
        )
        self._density_hist(
            neg[0], n=1, label='Presentation attack', alpha=0.4, color='C7',
            hatch='\\\\'
        )