Coverage for src/bob/bio/base/config/dummy/preprocessor.py: 0%

19 statements  

« prev     ^ index     » next       coverage.py v7.6.5, created at 2024-11-14 21:41 +0100

1import numpy 

2 

3from bob.bio.base.database import BioFile 

4from bob.bio.base.preprocessor import Preprocessor 

5 

6numpy.random.seed(10) 

7 

8 

9class DummyPreprocessor(Preprocessor): 

10 def __init__(self, return_none=False, probability_of_none=1, **kwargs): 

11 Preprocessor.__init__(self) 

12 self.return_none = return_none 

13 self.probability_of_none = probability_of_none 

14 

15 def __call__(self, data, annotation): 

16 """Does nothing, simply converts the data type of the data, ignoring any annotation.""" 

17 if self.return_none: 

18 return numpy.random.choice( 

19 [None, data], 

20 p=[self.probability_of_none, 1 - self.probability_of_none], 

21 ) 

22 

23 return data 

24 

25 

26preprocessor = DummyPreprocessor() 

27 

28 

29class DummyPreprocessorMetadata(DummyPreprocessor): 

30 def __call__(self, data, annotation, metadata=None): 

31 """Does nothing, simply converts the data type of the data, ignoring any annotation.""" 

32 assert isinstance(metadata, BioFile) 

33 return super(DummyPreprocessorMetadata, self).__call__(data, annotation) 

34 

35 

36preprocessor_metadata = DummyPreprocessorMetadata()