diff --git a/bob/bio/base/test/dummy/algorithm_noprojection.py b/bob/bio/base/test/dummy/algorithm_noprojection.py new file mode 100644 index 0000000000000000000000000000000000000000..69f0487dc7f3c71b62a764840c5a6085a5259fb4 --- /dev/null +++ b/bob/bio/base/test/dummy/algorithm_noprojection.py @@ -0,0 +1,46 @@ +import scipy.spatial +import bob.io.base + +from bob.bio.base.algorithm import Algorithm + +_data = [5., 6., 7., 8., 9.] + + +class DummyAlgorithm (Algorithm): + """This class is used to test all the possible functions of the tool chain, but it does basically nothing.""" + + def __init__(self, **kwargs): + """Generates a test value that is read and written""" + + # call base class constructor registering that this tool performs everything. + Algorithm.__init__( + self, + performs_projection=False, + requires_enroller_training=True + ) + + def _test(self, file_name): + """Simply tests that the read data is consistent""" + data = bob.io.base.load(file_name) + assert (_data == data).all() + + def train_enroller(self, train_files, enroller_file): + """Does not train the projector, but writes some file""" + # save something + bob.io.base.save(_data, enroller_file) + + def load_enroller(self, enroller_file): + """Loads the test value from file and compares it with the desired one""" + self._test(enroller_file) + + def enroll(self, enroll_features): + """Returns the first feature as the model""" + assert len(enroll_features) + # just return the first feature + return enroll_features[0] + + def score(self, model, probe): + """Returns the Euclidean distance between model and probe""" + return scipy.spatial.distance.euclidean(model, probe) + +algorithm = DummyAlgorithm() diff --git a/bob/bio/base/test/test_scripts.py b/bob/bio/base/test/test_scripts.py index 20cb89a943c4fc1a1b5bfeae42bb5bc9d7f44eba..effa0a043b1d0a5c6be20b11e00a41e234e7666e 100644 --- a/bob/bio/base/test/test_scripts.py +++ b/bob/bio/base/test/test_scripts.py @@ -82,6 +82,25 @@ def test_verify_config(): _verify(parameters, test_dir, 'test_config') +def test_verify_algorithm_noprojection(): + test_dir = tempfile.mkdtemp(prefix='bobtest_') + # define dummy parameters + parameters = [ + '-d', os.path.join(dummy_dir, 'database.py'), + '-p', os.path.join(dummy_dir, 'preprocessor.py'), + '-e', os.path.join(dummy_dir, 'extractor.py'), + '-a', os.path.join(dummy_dir, 'algorithm_noprojection.py'), + '--zt-norm', + '-vs', 'algorithm_noprojection', + '--temp-directory', test_dir, + '--result-directory', test_dir + ] + + print (bob.bio.base.tools.command_line(parameters)) + + _verify(parameters, test_dir, 'algorithm_noprojection') + + def test_verify_resources(): test_dir = tempfile.mkdtemp(prefix='bobtest_') # define dummy parameters