Skip to content
Snippets Groups Projects
Commit 04c20aa2 authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

manage to somehow create a table with Clients ...

parent a6472586
Branches
Tags
No related merge requests found
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
import os import os
from .models import * from .models import *
from bob.db.base.driver import Interface as BaseInterface
import bob.core import bob.core
logger = bob.core.log.setup('bob.db.fargo') logger = bob.core.log.setup('bob.db.fargo')
...@@ -24,8 +27,14 @@ def add_clients(session, imagesdir, verbose=True): ...@@ -24,8 +27,14 @@ def add_clients(session, imagesdir, verbose=True):
if verbose: if verbose:
logger.info("Adding clients ...") logger.info("Adding clients ...")
for d in os.listdir(imagesdir): for d in os.listdir(imagesdir):
print(d) client_id = int(d)
if client_id <= 25:
group = 'train'
elif client_id <= 50:
group = 'dev'
else:
group = 'eval'
session.add(Client(client_id, group))
def create_tables(args): def create_tables(args):
"""Creates all necessary tables (only to be used at the first time)""" """Creates all necessary tables (only to be used at the first time)"""
...@@ -43,6 +52,7 @@ def create(args): ...@@ -43,6 +52,7 @@ def create(args):
from bob.db.base.utils import session_try_nolock from bob.db.base.utils import session_try_nolock
print(args)
dbfile = args.files[0] dbfile = args.files[0]
if args.recreate: if args.recreate:
...@@ -74,7 +84,7 @@ def add_command(subparsers): ...@@ -74,7 +84,7 @@ def add_command(subparsers):
parser.add_argument('-v', '--verbose', action='count', default=0, parser.add_argument('-v', '--verbose', action='count', default=0,
help="Do SQL operations in a verbose way") help="Do SQL operations in a verbose way")
parser.add_argument('-i', '--imagesdir', action='store', parser.add_argument('-i', '--imagesdir', action='store',
default='/idiap/temp/heusch/bob.project.fargo/images/' default='/idiap/temp/heusch/bob.project.fargo/images/',
metavar='DIR', metavar='DIR',
help="Change the path to the extracted images of the FARGO database (defaults to %(default)s)") help="Change the path to the extracted images of the FARGO database (defaults to %(default)s)")
......
...@@ -71,19 +71,24 @@ class Interface(BaseInterface): ...@@ -71,19 +71,24 @@ class Interface(BaseInterface):
return pkg_resources.require('bob.db.%s' % self.name())[0].version return pkg_resources.require('bob.db.%s' % self.name())[0].version
def files(self): def files(self):
return () from pkg_resources import resource_filename
raw_files = ('db.sql3',)
return [resource_filename(__name__, k) for k in raw_files]
def type(self): def type(self):
return 'text' return 'sqlite'
def add_commands(self, parser): def add_commands(self, parser):
from . import __doc__ as docs from . import __doc__ as docs
subparsers = self.setup_parser(parser, subparsers = self.setup_parser(parser, "FARGO database", docs)
"FARGO database", docs)
import argparse import argparse
# example: get the "create" action from a submodule
from .create import add_command as create_command
create_command(subparsers)
# the "dumplist" action # the "dumplist" action
parser = subparsers.add_parser('dumplist', help=dumplist.__doc__) parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)
......
...@@ -2,13 +2,17 @@ ...@@ -2,13 +2,17 @@
# vim: set fileencoding=utf-8 : # vim: set fileencoding=utf-8 :
import os import os
from sqlalchemy import Table, Column, Integer, String, ForeignKey from sqlalchemy import Table, Column, Integer, String, ForeignKey
from bob.db.base.sqlalchemy_migration import Enum, relationship from bob.db.base.sqlalchemy_migration import Enum, relationship
from sqlalchemy.orm import backref from sqlalchemy.orm import backref
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
import bob.db.base
import numpy import numpy
import bob.io.base import bob.io.base
import bob.io.image import bob.io.image
import bob.core import bob.core
logger = bob.core.log.setup('bob.db.fargo') logger = bob.core.log.setup('bob.db.fargo')
...@@ -21,7 +25,7 @@ class Client(Base): ...@@ -21,7 +25,7 @@ class Client(Base):
__tablename__ = 'client' __tablename__ = 'client'
set_choices = ('train', 'devel', 'test') set_choices = ('train', 'dev', 'eval')
"""Possible groups to which clients may belong to""" """Possible groups to which clients may belong to"""
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
...@@ -38,7 +42,7 @@ class Client(Base): ...@@ -38,7 +42,7 @@ class Client(Base):
return "Client('%s', '%s')" % (self.id, self.set) return "Client('%s', '%s')" % (self.id, self.set)
class File(Base): class File(Base, bob.db.base.File):
"""Generic file container""" """Generic file container"""
__tablename__ = 'file' __tablename__ = 'file'
...@@ -59,6 +63,10 @@ class File(Base): ...@@ -59,6 +63,10 @@ class File(Base):
modality_choices = ('rgb', 'nir', 'depth') modality_choices = ('rgb', 'nir', 'depth')
modality = Column(Enum(*modality_choices)) modality = Column(Enum(*modality_choices))
# recordings
recording_choices = ('0', '1')
recording = Column(Enum(*recording_choices))
# shot (i.e. images extracted from the video sequence) # shot (i.e. images extracted from the video sequence)
# TODO: How to handle that with varying number of poses ? - Guillaume HEUSCH, 02-10-2018 # TODO: How to handle that with varying number of poses ? - Guillaume HEUSCH, 02-10-2018
shot_choices = tuple(['{:0>2d}'.format(s) for s in range(10)]) shot_choices = tuple(['{:0>2d}'.format(s) for s in range(10)])
...@@ -74,17 +82,16 @@ class File(Base): ...@@ -74,17 +82,16 @@ class File(Base):
# path of this file in the database # path of this file in the database
path = Column(String(100), unique=True) path = Column(String(100), unique=True)
# for Python
client = relationship(Client, backref=backref('files', order_by=id))
"""A direct link to the client object that this file belongs to"""
def __init__(self, client, path, light, device): def __init__(self, id_file, client_id, path):
self.client = client bob.db.base.File.__init__(self, path=path)
self.path = path self.id = id_file
self.client_id = client_id
self.light = light self.light = light
self.device = device self.device = device
self.pose = pose self.pose = pose
self.modality = modality self.modality = modality
self.recording = recording
self.shot = shot self.shot = shot
def __repr__(self): def __repr__(self):
...@@ -105,11 +112,9 @@ class File(Base): ...@@ -105,11 +112,9 @@ class File(Base):
Returns a string containing the newly generated file path. Returns a string containing the newly generated file path.
""" """
if not directory: if not directory:
directory = '' directory = ''
if not extension: if not extension:
extension = '' extension = ''
return str(os.path.join(directory, self.path + extension)) return str(os.path.join(directory, self.path + extension))
#!/usr/bin/env python #!/usr/bin/env python
# encoding: utf-8 # encoding: utf-8
import bob.bio.base import os
from bob.bio.face.database import FaceBioFile from bob.db.base import utils
from .models import *
class Database(bob.bio.base.database.FileListBioDatabase): #from .driver import Interface
"""Wrapper class for the FARGO database for face verification #INFO = Interface()
""" #SQLITE_FILE = INFO.files()[0]
def __init__(self, original_directory=None, original_extension=None, **kwargs): import bob.db.base
class Database(bob.db.base.SQLiteDatabase):
def __init__(self,
original_directory=None,
original_extension=None,
annotation_directory=None,
annotation_extension=None):
# call base class constructor # call base class constructor
from pkg_resources import resource_filename # File -> from models.py
folder = resource_filename(__name__, 'lists') super(Database, self).__init__(SQLITE_FILE, File, original_directory, original_extension)
super(Database, self).__init__(folder, 'fargo', bio_file_class=FaceBioFile,
original_directory=original_directory, self.annotation_directory = annotation_directory
original_extension=original_extension, **kwargs) self.annotation_extension = annotation_extension
def objects(self, protocol='mc-rgb', groups=None, modality='rgb'):
""" Return a set of file
Parameters
----------
protocol: py:obj:str
One of the protocols
groups: py:ojg:str or py:obj:tuple of py:obj:str
One of the groups ('world', 'dev', 'eval') or several of them
Returns
-------
py:obj:list
A list of File
Raises
------
"""
protocol = self.check_parameters_for_validity(protocol, "protocol", self.protocols())
groups = self.check_parameters_for_validity(groups, "group", self.groups())
retval = []
# training set: all images for the client id 1 to 25, controlled conditions, all device, all recordings
if 'train' in groups:
q = self.query(Client).join(File)
q = q.filter(Client.set.in_(groups))
retval += list(q)
...@@ -55,18 +55,6 @@ setup( ...@@ -55,18 +55,6 @@ setup(
'fargo = bob.db.fargo.driver:Interface', 'fargo = bob.db.fargo.driver:Interface',
], ],
'bob.bio.database' : [
'fargo_public_MC_RGB = bob.db.fargo.config:database_public_MC_RGB',
'fargo_public_UD_RGB = bob.db.fargo.config:database_public_UD_RGB',
'fargo_public_UO_RGB = bob.db.fargo.config:database_public_UO_RGB',
'fargo_public_MC_NIR = bob.db.fargo.config:database_public_MC_NIR',
'fargo_public_UD_NIR = bob.db.fargo.config:database_public_UD_NIR',
'fargo_public_UO_NIR = bob.db.fargo.config:database_public_UO_NIR',
'fargo_public_MC_depth = bob.db.fargo.config:database_public_MC_depth',
'fargo_public_UD_depth = bob.db.fargo.config:database_public_UD_depth',
'fargo_public_UO_depth = bob.db.fargo.config:database_public_UO_depth',
],
}, },
classifiers=[ classifiers=[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment