Commit eab48b7f authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Implement bio-grandtest0-voice protocol

parent e2ed2ffc
from .query import Database, SwanAudioBioFile, SwanVideoBioFile
from .query_bio import Database, SwanAudioBioFile, SwanVideoBioFile
def __appropriate__(*args):
......
import scipy.io.wavfile
import subprocess
import tempfile
from os.path import split, splitext
SITE_MAPPING = {
'1': 'NTNU',
'2': 'UIO',
'3': 'MPH-FRA',
'4': 'IDIAP',
'6': 'MPH-IND',
}
DEVICE_MAPPING = {
'p': 'iPhone',
't': 'iPad',
}
MODALITY_MAPPING = {
'1': 'face',
'2': 'voice',
'3': 'eye',
'4': 'finger',
}
def read_audio(video_path):
with tempfile.NamedTemporaryFile(suffix='.wav') as f:
cmd = ['ffmpeg', '-i', video_path, '-y', '-vn', f.name]
subprocess.call(cmd)
f.seek(0)
rate, signal = scipy.io.wavfile.read(f.name)
return rate, signal
class Client(object):
"""A base class for SWAN clients"""
def __init__(self, site, id_in_site, gender, **kwargs):
super(Client, self).__init__(**kwargs)
self.institute = site
self.id_in_site = int(id_in_site)
self.gender = gender
@property
def id(self):
return '{}_{}'.format(self.institute, self.id_in_site)
def swan_bio_file_metadata(path):
"""Returns the metadata associated with a SWAN file recorded during the
biometric recognition phase.
Parameters
----------
path : str
The path of the SWAN file.
Returns
-------
client : :any:`Client`
session : str
nrecording : str
device : str
modality : str
"""
# For example:
# path: IDIAP/session_01/iPad/00001/4_00001_m_01_01_t_2.mp4
_, path = split(path)
# path: 4_00001_m_01_01_t_2.mp4
path, extension = splitext(path)
# path: 4_00001_m_01_01_t_2
site, identity, gender, session, nrecording, device, modality = \
path.split('_')
site = SITE_MAPPING[site]
client = Client(site, identity, gender)
device = DEVICE_MAPPING[device]
modality = MODALITY_MAPPING[modality]
session = int(session)
return client, session, nrecording, device, modality
......@@ -6,6 +6,5 @@ swan_raw_data_directory = "[YOUR_SWAN_DIRECTORY]"
database = Database(
original_directory=swan_raw_data_directory,
original_extension=".mp4",
bio_file_class=SwanAudioBioFile,
)
......@@ -6,6 +6,5 @@ swan_raw_data_directory = "[YOUR_SWAN_DIRECTORY]"
database = Database(
original_directory=swan_raw_data_directory,
original_extension=".mp4",
bio_file_class=SwanVideoBioFile,
)
#!/usr/bin/env python
"""Commands the Swan database can respond to.
"""
import os
import sys
from bob.db.base.driver import Interface as BaseInterface
def dumplist(args):
"""Dumps lists of files based on your criteria"""
from .query import Database
db = Database()
r = db.objects(
purposes=args.purpose,
groups=args.group,
)
output = sys.stdout
if args.selftest:
from bob.db.base.utils import null
output = null()
for f in r:
output.write('%s\n' % f.make_path(
directory=args.directory, extension=args.extension))
return 0
def checkfiles(args):
"""Checks existence of files based on your criteria"""
from .query import Database
db = Database()
r = db.objects()
# go through all files, check if they are available on the filesystem
good = []
bad = []
for f in r:
if os.path.exists(f.make_path(args.directory, args.extension)):
good.append(f)
else:
bad.append(f)
# report
output = sys.stdout
if args.selftest:
from bob.db.base.utils import null
output = null()
if bad:
for f in bad:
output.write('Cannot find file "%s"\n' %
f.make_path(args.directory, args.extension))
output.write('%d files (out of %d) were not found at "%s"\n' %
(len(bad), len(r), args.directory))
return 0
class Interface(BaseInterface):
def name(self):
return 'swan'
def version(self):
import pkg_resources # part of setuptools
return pkg_resources.require('bob.db.%s' % self.name())[0].version
def files(self):
return ()
def type(self):
return 'text'
def add_commands(self, parser):
from . import __doc__ as docs
subparsers = self.setup_parser(parser,
"Swan database", docs)
import argparse
# the "dumplist" action
parser = subparsers.add_parser('dumplist', help=dumplist.__doc__)
parser.add_argument('-d', '--directory', default='',
help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', default='',
help="if given, this extension will be appended to every entry returned.")
parser.add_argument(
'-u', '--purpose', help="if given, this value will limit the output files to those designed for the given purposes.", choices=('enroll', 'probe', ''))
parser.add_argument('-g', '--group', help="if given, this value will limit the output files to those belonging to a particular protocolar group.",
choices=('dev', 'eval', 'world', ''))
parser.add_argument('--self-test', dest="selftest",
action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=dumplist) # action
# the "checkfiles" action
parser = subparsers.add_parser('checkfiles', help=checkfiles.__doc__)
parser.add_argument('-l', '--list-directory', required=True,
help="The directory which contains the file lists.")
parser.add_argument('-d', '--directory', dest="directory", default='',
help="if given, this path will be prepended to every entry returned.")
parser.add_argument('-e', '--extension', dest="extension", default='',
help="if given, this extension will be appended to every entry returned.")
parser.add_argument('--self-test', dest="selftest",
action='store_true', help=argparse.SUPPRESS)
parser.set_defaults(func=checkfiles) # action
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -31,8 +31,6 @@ setup(
install_requires=install_requires,
entry_points={
'bob.db': ['swan = bob.db.swan.driver:Interface'],
'bob.bio.database': ['swan-audio = bob.db.swan.config_audio:database'],
'bob.bio.database': ['swan-video = bob.db.swan.config_video:database'],
},
......
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