Coverage for src/bob/bio/face/config/baseline/dummy.py: 0%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-13 00:04 +0200

1from sklearn.pipeline import make_pipeline 

2from sklearn.preprocessing import FunctionTransformer 

3 

4from bob.bio.base.algorithm import Distance 

5from bob.bio.base.pipelines import PipelineSimple 

6from bob.bio.face.utils import lookup_config_from_database 

7from bob.pipelines import wrap 

8 

9( 

10 annotation_type, 

11 fixed_positions, 

12 memory_demanding, 

13) = lookup_config_from_database() 

14 

15from sklearn.base import BaseEstimator, TransformerMixin 

16 

17from bob.bio.face.color import rgb_to_gray 

18 

19 

20class ToGray(TransformerMixin, BaseEstimator): 

21 def transform(self, X, annotations=None): 

22 return [rgb_to_gray(data)[0:10, 0:10] for data in X] 

23 

24 def _more_tags(self): 

25 return {"requires_fit": False} 

26 

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

28 return self 

29 

30 

31def load(annotation_type, fixed_positions=None): 

32 transform_extra_arguments = (("annotations", "annotations"),) 

33 

34 transformer = make_pipeline( 

35 wrap( 

36 ["sample"], 

37 ToGray(), 

38 transform_extra_arguments=transform_extra_arguments, 

39 ), 

40 wrap( 

41 ["sample"], 

42 FunctionTransformer(lambda X: [x.flatten() for x in X]), 

43 ), 

44 ) 

45 

46 algorithm = Distance() 

47 

48 return PipelineSimple(transformer, algorithm) 

49 

50 

51pipeline = load(annotation_type, fixed_positions) 

52transformer = pipeline.transformer