DatabaseFileList.py 6.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# @author: Manuel Guenther <Manuel.Guenther@idiap.ch>
# @date: Wed Oct  3 10:31:51 CEST 2012
#
# Copyright (C) 2011-2012 Idiap Research Institute, Martigny, Switzerland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


from .DatabaseBob import DatabaseBobZT
22
import bob.db.verification.filelist
23
24

class DatabaseFileList (DatabaseBobZT):
25
26
27
28
29
30
31
32
33
34
35
36
  """This class can be used whenever you have a database that uses the Bob filelist database interface, which is defined in :py:class:`bob.db.verification.filelist.Database`

  **Parameters:**

  database : a :py:class:`bob.db.verification.filelist.Database`
    The database instance that provides the actual interface.

  kwargs : ``key=value`` pairs
    The arguments of the :py:class:`DatabaseBobZT` or :py:class:`DatabaseBob` base class constructors.

    .. note:: Usually, the ``name``, ``protocol``, ``training_depends_on_protocol`` and ``models_depend_on_protocol`` keyword parameters of the base class constructor need to be specified.
  """
37
38
39
40
41
42
43
44
45
46
47
48
49

  def __init__(
      self,
      database,  # The bob database that is used
      **kwargs  # The default parameters of the base class
  ):

    DatabaseBobZT.__init__(
        self,
        database = database,
        **kwargs
    )

50
51
    assert isinstance(database, bob.db.verification.filelist.Database)

52
53

  def all_files(self, groups = ['dev']):
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    """all_files(groups=None) -> files

    Returns all files of the database, respecting the current protocol.
    If the current protocol is ``'None'``, ``None`` will be used instead.
    When the underlying file list database provides files for ZT score normalization, these files are returned as well.
    The files can be limited using the ``all_files_options`` in the constructor.

    **Parameters:**

    groups : some of ``('world', 'dev', 'eval')`` or ``None``
      The groups to get the data for.
      If ``None``, data for all groups is returned.

    **Returns:**

    files : [:py:class:`bob.db.verification.filelist.File`]
      The sorted and unique list of all files of the database.
    """
    protocol = self.protocol if self.protocol != 'None' else None
    files = self.database.objects(protocol = protocol, groups = groups, **self.all_files_options)
74
75
76
77

    # add all files that belong to the ZT-norm
    for group in groups:
      if group == 'world': continue
78
79
80
      if self.database.implements_zt(protocol = protocol, groups = group):
        files += self.database.tobjects(protocol = protocol, groups = group, model_ids = None)
        files += self.database.zobjects(protocol = protocol, groups = group, **self.z_probe_options)
81
82
83
84
    return self.sort(files)


  def uses_probe_file_sets(self):
85
    """File sets are not (yet) supported in the :py:class:`bob.db.verification.filelist.Database`, so this function returns ``False`` throughout."""
86
87
88
89
    return False


  def model_ids(self, group = 'dev'):
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
    """model_ids(group = 'dev') -> ids

    Returns a list of model ids for the given group, respecting the current protocol.
    If the current protocol is ``'None'``, ``None`` will be used instead.

    **Parameters:**

    group : one of ``('dev', 'eval')``
      The group to get the model ids for.

    **Returns:**

    ids : [str]
      The list of (unique) model ids for the given group.
    """
105
106
107
108
    return sorted(self.database.model_ids(protocol = self.protocol if self.protocol != 'None' else None, groups = group))


  def client_id_from_model_id(self, model_id, group = 'dev'):
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    """client_id_from_model_id(model_id, group = 'dev') -> client_id

    Uses :py:meth:`bob.db.verification.filelist.Database.get_client_id_from_model_id` to retrieve the client id for the given model id.
    If the current protocol is ``'None'``, ``None`` will be used instead.

    **Parameters:**

    model_id : str
      A unique ID that identifies the model for the client.

    group : one of ``('dev', 'eval')``
      The group to get the client ids for.

    **Returns:**

    client_id : str
      A unique ID that identifies the client, to which the model belongs.
    """
127
128
129
130
    return self.database.get_client_id_from_model_id(model_id, groups = group, protocol = self.protocol if self.protocol != 'None' else None)


  def client_id_from_t_model_id(self, t_model_id, group = 'dev'):
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
    """client_id_from_t_model_idt_(model_id, group = 'dev') -> client_id

    Uses :py:meth:`bob.db.verification.filelist.Database.get_client_id_from_t_model_id` to retrieve the client id for the T-norm given model id.
    If the current protocol is ``'None'``, ``None`` will be used instead.

    **Parameters:**

    t_model_id : str
      A unique ID that identifies the T-Norm model.

    group : one of ``('dev', 'eval')``
      The group to get the client ids for.

    **Returns:**

    client_id : str
      A unique ID that identifies the client, to which the T-Norm model belongs.
    """
Manuel Günther's avatar
Manuel Günther committed
149
    return self.database.get_client_id_from_tmodel_id(t_model_id, groups = group, protocol = self.protocol if self.protocol != 'None' else None)
150
151
152


  def t_model_ids(self, group = 'dev'):
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    """t_model_ids(group = 'dev') -> ids

    Returns a list of model ids of T-Norm models for the given group, respecting the current protocol.
    If the current protocol is ``'None'``, ``None`` will be used instead.

    **Parameters:**

    group : one of ``('dev', 'eval')``
      The group to get the model ids for.

    **Returns:**

    ids : [int] or [str]
      The list of (unique) model ids for T-Norm models of the given group.
    """
168
    return sorted(self.database.tmodel_ids(protocol = self.protocol if self.protocol != 'None' else None, groups = group))