Coverage for src/bob/bio/base/transformers/preprocessor.py: 81%
16 statements
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 21:41 +0100
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 21:41 +0100
1#!/usr/bin/env python
2# vim: set fileencoding=utf-8 :
4from sklearn.base import BaseEstimator, TransformerMixin
6from bob.bio.base.preprocessor import Preprocessor
9class PreprocessorTransformer(TransformerMixin, BaseEstimator):
10 """Scikit learn transformer for :py:class:`bob.bio.base.preprocessor.Preprocessor`.
12 Parameters
13 ----------
14 instance: object
15 An instance of `bob.bio.base.preprocessor.Preprocessor`
16 """
18 def __init__(
19 self,
20 instance,
21 **kwargs,
22 ):
23 if not isinstance(instance, Preprocessor):
24 raise ValueError(
25 "`instance` should be an instance of `bob.bio.base.preprocessor.Preprocessor`"
26 )
28 self.instance = instance
29 super().__init__(**kwargs)
31 def transform(self, X, annotations=None):
32 if annotations is None:
33 return [self.instance(data) for data in X]
34 else:
35 return [
36 self.instance(data, annot)
37 for data, annot in zip(X, annotations)
38 ]
40 def _more_tags(self):
41 return {
42 "requires_fit": False,
43 "bob_features_save_fn": self.instance.write_data,
44 "bob_features_load_fn": self.instance.read_data,
45 }
47 def fit(self, X, y=None):
48 return self