preprocessor.py 1.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

from sklearn.base import TransformerMixin, BaseEstimator
from bob.bio.base.preprocessor import Preprocessor

class PreprocessorTransformer(TransformerMixin, BaseEstimator):
    """
    Scikit learn transformer for :any:`bob.bio.base.preprocessor.Preprocessor`.

    Parameters
    ----------

14
      instance: object
15
         An instance of `bob.bio.base.preprocessor.Preprocessor`
16
17
18
19
20
21


    """

    def __init__(
        self,
22
        instance,
23
24
25
        **kwargs,
    ):

26
27
        if not isinstance(instance, Preprocessor):
            raise ValueError("`instance` should be an instance of `bob.bio.base.preprocessor.Preprocessor`")
28

29
        self.instance = instance
30
31
32
33
        super().__init__(**kwargs)

    def transform(self, X, annotations=None):
        if annotations is None:
34
            return [self.instance(data) for data in X]
35
        else:
36
            return [self.instance(data, annot) for data, annot in zip(X, annotations)]
37
38
39

    def _more_tags(self):
        return {"stateless": True, "requires_fit": False}
40
41
42

    def fit(self, X, y=None):
        return self