database.py 2.46 KB
Newer Older
1
from bob.bio.base.database import ZTBioDatabase
2
from bob.bio.base.test.utils import atnt_database_directory
3 4 5 6 7 8 9 10 11 12 13 14 15
from bob.bio.base.database.file import BioFile
from bob.bio.video.database import VideoBioFile
from bob.bio.video.utils import FrameContainer
import bob.io.base
import os


class DummyBioFile(VideoBioFile):
    def load(self, directory=None, extension='.avi'):
        file_name = self.make_path(directory, extension)
        fc = FrameContainer()
        fc.add(os.path.basename(file_name), bob.io.base.load(file_name))
        return fc
16 17


18 19 20 21 22 23 24 25 26 27 28 29
class DummyDatabase(ZTBioDatabase):

    def __init__(self):
        # call base class constructor with useful parameters
        super(DummyDatabase, self).__init__(
            name='test',
            original_directory=atnt_database_directory(),
            original_extension='.pgm',
            check_original_files_for_existence=True,
            training_depends_on_protocol=False,
            models_depend_on_protocol=False
        )
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
30 31
        import bob.db.atnt
        self.__db = bob.db.atnt.Database()
32

33 34 35
    def _make_bio(self, files):
      return [DummyBioFile(BioFile(client_id=f.client_id, path=f.path, file_id=f.id)) for f in files]

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
36 37
    def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
        return self.__db.model_ids(groups, protocol)
38 39

    def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
40
        return self._make_bio(self.__db.objects(model_ids, groups, purposes, protocol, **kwargs))
41 42 43

    def tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs):
        return []
44

45 46
    def zobjects(self, groups=None, protocol=None, **kwargs):
        return []
47

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
48
    def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
49
        return self.__db.model_ids(groups)
50

51
    def t_enroll_files(self, t_model_id, group='dev'):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
52
        return self.enroll_files(t_model_id, group)
53

54
    def z_probe_files(self, group='dev'):
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
55
        return self.probe_files(None, group)
56

57
    # override all_files to return a one-element lists of files
58 59 60
    #def all_files(self, groups):
        #return [[n] for n in super(DummyDatabase, self).all_files(groups)]
        #return [[n] for n in super(DummyDatabase, self).all_files(groups)]
61

62 63 64 65
    def file_names(self, files, directory, extension):
        if isinstance(files[0], list):
            files = list(list(zip(*files))[0])
        return super(DummyDatabase, self).file_names(files, directory, extension)
66 67

database = DummyDatabase()