Commit 48e059f9 authored by Manuel Günther's avatar Manuel Günther
Browse files

Adapted database to new xbob.db.verification.utils interface; added...

Adapted database to new xbob.db.verification.utils interface; added annotation() function that reads annotation files.
parent 26e892c8
......@@ -23,7 +23,7 @@ from setuptools import setup, find_packages
setup(
name='xbob.db.mobio',
version='1.1.2a0',
version='1.2.1a0',
description='MOBIO Database Access API for Bob',
url='https://pypi.python.org/pypi/xbob.db.mobio',
license='GPLv3',
......@@ -39,9 +39,9 @@ setup(
install_requires=[
'setuptools',
'six', # py2/3 compatibility library
'six', # py2/3 compatibility library
'bob', # base signal proc./machine learning library
'xbob.db.verification.utils>=0.1.4' # defines a set of utilities for face verification databases like this one.
'xbob.db.verification.utils>=1.0.0' # defines a set of utilities for face verification databases like this one.
],
namespace_packages = [
......@@ -59,7 +59,7 @@ setup(
'bob.test': [
'mobio = xbob.db.mobio.test:MobioDatabaseTest',
],
# scripts
# scripts
'console_scripts': [
'generate_filelist = xbob.db.mobio.generate_filelist:main',
],
......
......@@ -37,10 +37,13 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
and for the data itself inside the database.
"""
def __init__(self):
def __init__(self, original_directory = None, original_extension = None, annotation_directory = None, annotation_extension = '.pos'):
# call base class constructors to open a session to the database
xbob.db.verification.utils.SQLiteDatabase.__init__(self, SQLITE_FILE, File)
xbob.db.verification.utils.ZTDatabase.__init__(self)
xbob.db.verification.utils.ZTDatabase.__init__(self, original_directory=original_directory, original_extension=original_extension)
self.annotation_directory = annotation_directory
self.annotation_extension = annotation_extension
def groups(self):
"""Returns the names of all registered groups"""
......@@ -78,9 +81,9 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
def _replace_protocols_alias(self, protocol):
#print(protocol)
if protocol:
if protocol:
from six import string_types
if isinstance(protocol, string_types):
if isinstance(protocol, string_types):
#print([self._replace_protocol_alias(protocol)])
return [self._replace_protocol_alias(protocol)]
else:
......@@ -482,7 +485,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
device
The device choice to consider ('mobile', 'laptop')
Returns: A set of Files with the given properties.
"""
......@@ -512,7 +515,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
q = q.filter(File.device.in_(device))
q = q.order_by(File.client_id, File.session_id, File.speech_type, File.shot_id, File.device)
retval = [v[0] for v in q]
return list(retval)
return list(retval)
def zobjects(self, protocol=None, model_ids=None, groups=None, subworld='onethird', gender=None, speech_type=['r','f'], device=['mobile']):
"""Returns a set of Files to perform Z-norm score normalization.
......@@ -546,7 +549,7 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
device
The device choice to consider ('mobile', 'laptop')
Returns: A set of Files with the given properties.
"""
......@@ -580,6 +583,31 @@ class Database(xbob.db.verification.utils.SQLiteDatabase, xbob.db.verification.u
q = q.order_by(File.client_id, File.session_id, File.speech_type, File.shot_id, File.device)
return list(q)
def annotations(self, file_id):
"""Reads the annotations for the given file id from file and returns them in a dictionary.
If you don't have a copy of the annotation files, you can download them under http://www.idiap.ch/resource/biometric.
Keyword parameters:
file_id
The ID of the file for which the annotations should be read.
Return value
The annotations as a dictionary: {'reye':(re_y,re_x), 'leye':(le_y,le_x)}
"""
if self.annotation_directory is None:
return None
self.assert_validity()
query = self.query(File).filter(File.id==file_id)
assert query.count() == 1
annotation_file = query.first().make_path(self.annotation_directory, self.annotation_extension)
# return the annotations as read from file
return xbob.db.verification.utils.read_annotation_file(annotation_file, 'eyecenter')
def protocol_names(self):
"""Returns all registered protocol names"""
......
......@@ -22,6 +22,7 @@
import os, sys
import unittest
from .query import Database
from nose.plugins.skip import SkipTest
class MobioDatabaseTest(unittest.TestCase):
"""Performs various tests on the MOBIO database."""
......@@ -107,7 +108,7 @@ class MobioDatabaseTest(unittest.TestCase):
def test03_objects(self):
db = Database()
# Protocol mobile0-female
# World group
self.assertEqual(len(db.objects(protocol='mobile0-female', groups='world')), 9600)
......@@ -364,7 +365,7 @@ class MobioDatabaseTest(unittest.TestCase):
# T-Norm and Z-Norm files
# T-Norm
# T-Norm
self.assertEqual(len(db.tobjects(protocol='mobile0-female')), 3072)
self.assertEqual(len(db.tobjects(protocol='mobile0-male')), 3072)
self.assertEqual(len(db.tobjects(protocol='mobile1-female')), 3408)
......@@ -376,14 +377,32 @@ class MobioDatabaseTest(unittest.TestCase):
self.assertEqual(len(db.tobjects(protocol='male', speech_type='p')), 960)
self.assertEqual(len(db.tobjects(protocol='female', speech_type='p')), 960)
self.assertEqual(len(db.tobjects(protocol='male', speech_type='p', model_ids=('204_01_mobile',))), 5)
# Z-Norm files
self.assertEqual(len(db.zobjects()), 1920)
self.assertEqual(len(db.zobjects(model_ids=(204,))), 120)
self.assertEqual(len(db.zobjects(protocol='male', speech_type=['p','r','l','f'])), 3072)
self.assertEqual(len(db.zobjects(protocol='male', speech_type=['p','r','l','f'], model_ids=(204,))), 192)
def test04_driver_api(self):
def test04_annotations(self):
# read some annotation files and test it's content
dir = "/idiap/resource/database/mobio/IMAGE_ANNOTATIONS"
if not os.path.exists(dir):
raise SkipTest("The annotation directory '%d' is not available, annotations can't be tested.")
db = Database(annotation_directory = dir)
import random
files = random.sample(db.all_files(), 1000)
for file in files:
annotations = db.annotations(file.id)
self.assertTrue(annotations is not None)
self.assertTrue('leye' in annotations)
self.assertTrue('reye' in annotations)
self.assertEqual(len(annotations['leye']), 2)
self.assertEqual(len(annotations['reye']), 2)
def test05_driver_api(self):
from bob.db.script.dbmanage import main
self.assertEqual(main('mobio dumplist --self-test'.split()), 0)
......
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