Predictions.py 1.17 KB
Newer Older
1
from bob.pad.base.algorithm import Algorithm
2
import numpy
3 4 5 6 7 8 9


class Predictions(Algorithm):
    """An algorithm that takes the precomputed predictions and uses them for
    scoring."""

    def __init__(self, **kwargs):
10
        super(Predictions, self).__init__(**kwargs)
11 12

    def score(self, predictions):
13 14 15 16
        predictions = numpy.asarray(predictions)
        if predictions.size == 1:
            # output of a sigmoid binary layer
            return predictions
17 18
        # Assuming the predictions are the output of a softmax layer
        return [predictions[1]]
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37


class VideoPredictions(Algorithm):
    """An algorithm that takes the precomputed predictions and uses them for
    scoring."""

    def __init__(self, axis=1, frame_level_scoring=False, **kwargs):
        super(VideoPredictions, self).__init__(**kwargs)
        self.frame_level_scoring = frame_level_scoring
        self.axis = axis

    def score(self, predictions):
        # Assuming the predictions are the output of a softmax layer
        predictions = predictions.as_array()[:, self.axis]

        if self.frame_level_scoring:
            return predictions
        else:
            return [numpy.mean(predictions)]