Commit a093c910 authored by Pedro TOME's avatar Pedro TOME
Browse files

New version defined to BEAT Platform

parent d46da634
......@@ -23,7 +23,7 @@ from setuptools import setup, find_packages
setup(
name='xbob.db.utfvp',
version='1.1.0',
version='2.0.0',
description='UTFVP Database Access API for Bob',
url='https://pypi.python.org/pypi/xbob.db.utfvp',
license='GPLv3',
......
This diff is collapsed.
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
# Laurent El Shafey <laurent.el-shafey@idiap.ch>
# Wed Feb 19 12:31:20 CET 2014
#
# Copyright (C) 2014 Idiap Research Institute, Martigny, Switzerland
#
......@@ -31,10 +31,14 @@ def dumplist(args):
from .query import Database
db = Database()
model_ids = None
if args.models is not None:
if isinstance(args.models, (list, tuple)): model_ids = args.models
else: model_ids = (args.models,)
r = db.objects(
protocol=args.protocol,
purposes=args.purpose,
model_ids=(args.models,),
model_ids=model_ids,
groups=args.group,
classes=args.sclass
)
......
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
# Laurent El Shafey <laurent.el-shafey@idiap.ch>
#
# Copyright (C) 2014 Idiap Research Institute, Martigny, Switzerland
......@@ -30,14 +31,24 @@ import xbob.db.verification.utils
Base = declarative_base()
protocolPurpose_file_association = Table('protocolPurpose_file_association', Base.metadata,
Column('protocolPurpose_id', Integer, ForeignKey('protocolPurpose.id')),
Column('file_id', Integer, ForeignKey('file.id')))
protocol_model_association = Table('protocol_model_association', Base.metadata,
Column('protocol_id', Integer, ForeignKey('protocol.id')),
Column('model_id', Integer, ForeignKey('model.id')))
protocol_trainfiles_association = Table('protocol_trainfiles_association', Base.metadata,
Column('protocol_id', Integer, ForeignKey('protocol.id')),
Column('file_id', Integer, ForeignKey('file.id')))
model_probefile_association = Table('model_probefile_association', Base.metadata,
Column('model_id', Integer, ForeignKey('model.id')),
Column('file_id', Integer, ForeignKey('file.id')))
model_enrollmentfile_association = Table('model_enrollmentfile_association', Base.metadata,
Column('model_id', Integer, ForeignKey('model.id')),
Column('file_id', Integer, ForeignKey('file.id')))
class Client(Base):
"""Database clients, marked by an integer identifier and the group they belong to"""
......@@ -63,23 +74,26 @@ class Model(Base):
id = Column(Integer, primary_key=True)
# Name of the protocol associated with this object
name = Column(String(20))
# Group associated with this protocol purpose object
group_choices = ('dev', 'eval')
sgroup = Column(Enum(*group_choices))
# Key identifier of the client associated with this model
client_id = Column(String(20), ForeignKey('client.id')) # for SQL
# Key identifier of the enrollment associated with this model
file_id = Column(Integer, ForeignKey('file.id')) # for SQL
# For Python: A direct link to the enrollment File objects associated with this Model
enrollment_files = relationship("File", secondary=model_enrollmentfile_association, backref=backref("models_enroll", order_by=id))
# For Python: A direct link to the probe File objects associated with this Model
probe_files = relationship("File", secondary=model_probefile_association, backref=backref("models_probe", order_by=id))
# For Python: A direct link to the client object that this model belongs to
client = relationship("Client", backref=backref("models", order_by=id))
# For Python: A direct link to the enrollment file object that this model belongs to
file = relationship("File", backref=backref("models", order_by=id))
def __init__(self, name, client_id, file_id):
def __init__(self, name, client_id, sgroup):
self.name = name
self.client_id = client_id
self.file_id = file_id
self.sgroup = sgroup
def __repr__(self):
return "Model(%s)" % (self.name,)
return "Model(%s, %s)" % (self.name, self.sgroup)
class File(Base, xbob.db.verification.utils.File):
"""Generic file container"""
......@@ -92,9 +106,6 @@ class File(Base, xbob.db.verification.utils.File):
client_id = Column(String(20), ForeignKey('client.id')) # for SQL
# Unique path to this file inside the database
path = Column(String(100), unique=True)
# Group id
group_choices = ('world', 'dev')
sgroup = Column(Enum(*group_choices))
# Identifier of the claimed client associated with this file
finger_id = Column(Integer)
# Identifier of the session
......@@ -103,10 +114,10 @@ class File(Base, xbob.db.verification.utils.File):
# For Python: A direct link to the client object that this file belongs to
client = relationship("Client", backref=backref("files", order_by=id))
def __init__(self, client_id, path, sgroup, finger_id, session_id):
def __init__(self, client_id, path, finger_id, session_id):
# call base class constructor
xbob.db.verification.utils.File.__init__(self, client_id = client_id, path = path)
self.sgroup = sgroup
#self.sgroup = sgroup
self.finger_id = finger_id
self.session_id = session_id
......@@ -120,8 +131,9 @@ class Protocol(Base):
# Name of the protocol associated with this object
name = Column(String(20), unique=True)
# For Python: A direct link to the Model objects associated with this Protcol
models = relationship("Model", secondary=protocol_model_association, backref=backref("protocols", order_by=id))
# For Python: A direct link to the DevModel objects associated with this Protcol
train_files = relationship("File", secondary=protocol_trainfiles_association, backref=backref("protocols_train", order_by=id))
models = relationship("Model", secondary=protocol_model_association, backref=backref("protocol", uselist=False, order_by=id))
def __init__(self, name):
self.name = name
......@@ -129,32 +141,3 @@ class Protocol(Base):
def __repr__(self):
return "Protocol('%s')" % (self.name,)
class ProtocolPurpose(Base):
"""UTFVP protocol purposes"""
__tablename__ = 'protocolPurpose'
# Unique identifier for this protocol purpose object
id = Column(Integer, primary_key=True)
# Id of the protocol associated with this protocol purpose object
protocol_id = Column(Integer, ForeignKey('protocol.id')) # for SQL
# Group associated with this protocol purpose object
group_choices = ('world', 'dev')
sgroup = Column(Enum(*group_choices))
# Purpose associated with this protocol purpose object
purpose_choices = ('train', 'enrol', 'probe')
purpose = Column(Enum(*purpose_choices))
# For Python: A direct link to the Protocol object that this ProtocolPurpose belongs to
protocol = relationship("Protocol", backref=backref("purposes", order_by=id))
# For Python: A direct link to the File objects associated with this ProtcolPurpose
files = relationship("File", secondary=protocolPurpose_file_association, backref=backref("protocolPurposes", order_by=id))
def __init__(self, protocol_id, sgroup, purpose):
self.protocol_id = protocol_id
self.sgroup = sgroup
self.purpose = purpose
def __repr__(self):
return "ProtocolPurpose('%s', '%s', '%s')" % (self.protocol.name, self.sgroup, self.purpose)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Pedro Tome <Pedro.Tome@idiap.ch>
# Laurent El Shafey <Laurent.El-Shafey@idiap.ch>
#
# Copyright (C) 2014 Idiap Research Institute, Martigny, Switzerland
......@@ -43,8 +44,8 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
def groups(self, protocol=None):
"""Returns the names of all registered groups"""
return File.group_choices
if protocol == '1vsall': return ('world', 'dev')
else: return ('world', 'dev', 'eval')
def clients(self, protocol=None, groups=None):
"""Returns a set of clients for the specific query by the user.
......@@ -52,23 +53,32 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
Keyword Parameters:
protocol
One of the UTFVP protocols ('master', 'paper').
One of the UTFVP protocols ('1vsall', 'nom','nomLeftRing','nomLeftMiddle','nomLeftIndex','nomRightIndex','nomRightMiddle','nomRightRing').
groups
ignored (The clients belong both to 'world' and 'dev')
Returns: A list containing all the clients which have the given properties.
"""
protocols = self.check_parameters_for_validity(protocol, "protocol", self.protocol_names())
groups = self.check_parameters_for_validity(groups, "group", self.groups())
retval = []
# List of the clients
q = self.query(Client)
if len(protocols) == 1 and protocols[0] == 'master':
q = q.filter(not_(Client.id.in_(('19_1', '19_2', '19_3', '19_4', '19_5', '19_6'))))
q = q.order_by(Client.id)
retval += list(q)
if 'world' in groups:
q = self.query(Client).join((File, Client.files)).join((Protocol, File.protocols_train)).filter(Protocol.name.in_(protocols))
q = q.order_by(Client.id)
retval += list(q)
if 'dev' in groups or 'eval' in groups:
q = self.query(Client).join((Model, Client.models)).join((Protocol, Model.protocol)).filter(Protocol.name.in_(protocols))
q = q.filter(Model.sgroup.in_(groups))
q = q.order_by(Client.id)
retval += list(q)
if len(protocols) == len(self.protocols()):
retval = list(self.query(Client))
return retval
......@@ -78,10 +88,10 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
Keyword Parameters:
protocol
One of the UTFVP protocols ('master', 'paper').
One of the UTFVP protocols ('1vsall', 'nom','nomLeftRing','nomLeftMiddle','nomLeftIndex','nomRightIndex','nomRightMiddle','nomRightRing').
groups
ignored (The clients belong both to 'world' and 'dev')
The clients belong to ('world', 'dev' and 'eval')
Returns: A list containing all the clients which have the given properties.
"""
......@@ -94,12 +104,11 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
Keyword Parameters:
protocol
One of the UTFVP protocols ('master', 'paper').
One of the UTFVP protocols ('1vsall', 'nom','nomLeftRing','nomLeftMiddle','nomLeftIndex','nomRightIndex','nomRightMiddle','nomRightRing').
groups
Returns models from the 'dev' if None or 'dev' are given.
Nothing otherwise
Returns models from the 'dev' or 'eval.
Returns: A list containing all the models which have the given properties.
"""
......@@ -107,12 +116,12 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
groups = self.check_parameters_for_validity(groups, "group", self.groups())
retval = []
if 'dev' in groups:
if 'dev' in groups or 'eval' in groups:
# List of the clients
q = self.query(Model).join((Protocol, Model.protocols)).filter(Protocol.name.in_(protocols))
q = q.order_by(Model.name)
q = self.query(Model).join((Protocol, Model.protocol)).filter(Protocol.name.in_(protocols))
q = q.filter(Model.sgroup.in_(groups)).order_by(Model.name)
retval += list(q)
return retval
def model_ids(self, protocol=None, groups=None):
......@@ -121,10 +130,10 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
Keyword Parameters:
protocol
Two possible protocols: 'paper' or 'master'
Eight possible protocols: '1vsall', 'nom','nomLeftRing','nomLeftMiddle','nomLeftIndex','nomRightIndex','nomRightMiddle','nomRightRing'
groups
The groups to which the subjects attached to the models belong ('dev')
The groups to which the subjects attached to the models belong ('world', dev', 'eval')
Returns: A list containing all the models ids which have the given properties.
"""
......@@ -152,8 +161,8 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
Returns: The client_id attached to the given model_id
"""
return self.query(Model).filter(Model.name==model_id).one().client_id
return self.query(Model).filter(Model.name==model_id).first().client_id
def objects(self, protocol=None, purposes=None, model_ids=None, groups=None,
classes=None, finger_ids=None, session_ids=None):
......@@ -162,7 +171,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
Keyword Parameters:
protocol
One of the UTFVP protocols ('master', 'paper').
One of the UTFVP protocols ('1vsall', 'nom','nomLeftRing','nomLeftMiddle','nomLeftIndex','nomRightIndex','nomRightMiddle','nomRightRing').
purposes
The purposes required to be retrieved ('enrol', 'probe', 'train') or a tuple
......@@ -176,7 +185,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
the model_ids is performed.
groups
One of the groups ('dev', 'world') or a tuple with several of them.
One of the groups ('world', dev', 'eval') or a tuple with several of them.
If 'None' is given (this is the default), it is considered the same as a
tuple with all possible values.
......@@ -221,19 +230,23 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
# Now query the database
retval = []
if 'world' in groups:
q = self.query(File).join((ProtocolPurpose, File.protocolPurposes)).join(Protocol).\
filter(and_(Protocol.name.in_(protocols), ProtocolPurpose.sgroup == 'world'))
#filter(File.sgroup == 'world')
q = self.query(File).join((Protocol, File.protocols_train)).\
filter(Protocol.name.in_(protocols))
if finger_ids: q = q.filter(File.finger_id.in_(finger_ids))
if session_ids: q = q.filter(File.session_id.in_(session_ids))
q = q.order_by(File.client_id, File.finger_id, File.session_id)
retval += list(q)
if 'dev' in groups:
if 'dev' in groups or 'eval' in groups:
sgroups = []
if 'dev' in groups: sgroups.append('dev')
if 'eval' in groups: sgroups.append('eval')
if 'enrol' in purposes:
q = self.query(File).join(Client).join((ProtocolPurpose, File.protocolPurposes)).join(Protocol).\
filter(and_(Protocol.name.in_(protocols), ProtocolPurpose.sgroup == 'dev', ProtocolPurpose.purpose == 'enrol'))
if model_ids: q = q.join((Model, File.models)).filter(Model.name.in_(model_ids))
q = self.query(File).join(Client).join((Model, File.models_enroll)).join((Protocol, Model.protocol)).\
filter(and_(Protocol.name.in_(protocols), Model.sgroup.in_(sgroups)))
if model_ids:
q = q.filter(Model.name.in_(model_ids))
if finger_ids: q = q.filter(File.finger_id.in_(finger_ids))
if session_ids: q = q.filter(File.session_id.in_(session_ids))
q = q.order_by(File.client_id, File.finger_id, File.session_id)
......@@ -241,22 +254,20 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
if 'probe' in purposes:
if 'client' in classes:
q = self.query(File).join(Client).join((ProtocolPurpose, File.protocolPurposes)).join(Protocol).\
filter(and_(Protocol.name.in_(protocols), ProtocolPurpose.sgroup == 'dev', ProtocolPurpose.purpose == 'probe'))
if len(model_ids) != 0: # Optimization using prior knowledge on the protocol to avoid long query in this case
q = q.join((Model, Protocol.models)).filter(and_(File.client_id == Model.client_id, File.id != Model.file_id))
if model_ids: q = q.filter(Model.name.in_(model_ids))
q = self.query(File).join(Client).join((Model, File.models_probe)).join((Protocol, Model.protocol)).\
filter(and_(Protocol.name.in_(protocols), Model.sgroup.in_(sgroups), File.client_id == Model.client_id))
if model_ids:
q = q.filter(Model.name.in_(model_ids))
if finger_ids: q = q.filter(File.finger_id.in_(finger_ids))
if session_ids: q = q.filter(File.session_id.in_(session_ids))
q = q.order_by(File.client_id, File.finger_id, File.session_id)
retval += list(q)
if 'impostor' in classes:
q = self.query(File).join(Client).join((ProtocolPurpose, File.protocolPurposes)).join(Protocol).\
filter(and_(Protocol.name.in_(protocols), ProtocolPurpose.sgroup == 'dev', ProtocolPurpose.purpose == 'probe'))
if len(model_ids) != 0: # Optimization using prior knowledge on the protocol to avoid long query in this case
q = q.join((Model, Protocol.models)).filter(File.client_id != Model.client_id)
if model_ids: q = q.filter(Model.name.in_(model_ids))
q = self.query(File).join(Client).join((Model, File.models_probe)).join((Protocol, Model.protocol)).\
filter(and_(Protocol.name.in_(protocols), Model.sgroup.in_(sgroups), File.client_id != Model.client_id))
if len(model_ids) != 0:
q = q.filter(Model.name.in_(model_ids))
if finger_ids: q = q.filter(File.finger_id.in_(finger_ids))
if session_ids: q = q.filter(File.session_id.in_(session_ids))
q = q.order_by(File.client_id, File.finger_id, File.session_id)
......@@ -288,4 +299,6 @@ class Database(xbob.db.verification.utils.SQLiteDatabase):
return self.query(Protocol).filter(Protocol.name==name).one()
def purposes(self):
return ProtocolPurpose.purpose_choices
return ('train', 'enrol', 'probe')
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment