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
« prev ^ index » next coverage.py v7.6.5, created at 2024-11-14 21:41 +0100
1import numpy
3from bob.bio.base.database import BioFile
4from bob.bio.base.preprocessor import Preprocessor
6numpy.random.seed(10)
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
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 )
23 return data
26preprocessor = DummyPreprocessor()
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)
36preprocessor_metadata = DummyPreprocessorMetadata()