Commit c9d5d74b authored by Amir MOHAMMADI's avatar Amir MOHAMMADI
Browse files

Merge branch 'refactoring_2016' into 'master'

Implements the annotations

See merge request !11
parents 080c64d7 b618793c
Pipeline #6448 passed with stages
in 14 minutes and 50 seconds
.. vim: set fileencoding=utf-8 :
.. Fri 26 Aug 16:12:17 CEST 2016
.. image:: http://img.shields.io/badge/docs-stable-yellow.png
.. image:: http://img.shields.io/badge/docs-stable-yellow.svg
:target: http://pythonhosted.org/bob.bio.video/index.html
.. image:: http://img.shields.io/badge/docs-latest-orange.png
.. image:: http://img.shields.io/badge/docs-latest-orange.svg
:target: https://www.idiap.ch/software/bob/docs/latest/bob/bob.bio.video/master/index.html
.. image:: https://gitlab.idiap.ch/bob/bob.bio.video/badges/master/build.svg
:target: https://gitlab.idiap.ch/bob/bob.bio.video/commits/master
......@@ -46,5 +46,5 @@ development `mailing list`_.
.. Place your references here:
.. _bob: https://www.idiap.ch/software/bob
.. _installation: https://gitlab.idiap.ch/bob/bob/wikis/Installation
.. _installation: https://www.idiap.ch/software/bob/install
.. _mailing list: https://groups.google.com/forum/?fromgroups#!forum/bob-devel
\ No newline at end of file
......@@ -15,5 +15,5 @@ class VideoBioFile(BioFile):
"""
super(VideoBioFile, self).__init__(client_id=client_id, path=path, file_id=file_id)
def load(self, directory=None, extension='.avi', frame_selector = FrameSelector()):
def load(self, directory=None, extension='.avi', frame_selector=FrameSelector()):
return frame_selector(self.make_path(directory, extension))
......@@ -10,39 +10,63 @@
"""
from .database import VideoBioFile
from bob.bio.base.database import ZTBioDatabase, BioFile
from bob.bio.base.database import ZTBioDatabase
class MobioBioFile(VideoBioFile):
def __init__(self, f):
super(MobioBioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id)
self._f = f
class MobioBioDatabase(ZTBioDatabase):
"""
Implements verification API for querying Mobio database.
MOBIO database implementation of bob.bio.base.database.ZTDatabase interface.
It is an extension of an SQL-based database interface, which directly talks to Mobio database, for
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
original_extension=None,
annotation_directory=None,
annotation_extension='.pos',
**kwargs
):
# call base class constructors to open a session to the database
super(MobioBioDatabase, self).__init__(name='mobio',
**kwargs)
super(MobioBioDatabase, self).__init__(
name='mobio',
original_directory=original_directory,
original_extension=original_extension,
annotation_directory=annotation_directory,
annotation_extension=annotation_extension,
**kwargs)
from bob.db.mobio.query import Database as LowLevelDatabase
self.__db = LowLevelDatabase()
self._db = LowLevelDatabase(original_directory,
original_extension,
annotation_directory,
annotation_extension)
def model_ids_with_protocol(self, groups=None, protocol=None, gender=None):
return self.__db.model_ids(groups=groups, protocol=protocol, gender=gender)
return self._db.model_ids(groups=groups, protocol=protocol, gender=gender)
def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
return self.__db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
return self._db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
retval = self.__db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)
return [VideoBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in retval]
retval = self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)
return [MobioBioFile(f) for f in retval]
def tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs):
retval = self.__db.tobjects(groups=groups, protocol=protocol, model_ids=model_ids, **kwargs)
return [VideoBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in retval]
retval = self._db.tobjects(groups=groups, protocol=protocol, model_ids=model_ids, **kwargs)
return [MobioBioFile(f) for f in retval]
def zobjects(self, groups=None, protocol=None, **kwargs):
retval = self.__db.zobjects(groups=groups, protocol=protocol, **kwargs)
return [VideoBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in retval]
retval = self._db.zobjects(groups=groups, protocol=protocol, **kwargs)
return [MobioBioFile(f) for f in retval]
def annotations(self, myfile):
return self._db.annotations(myfile._f)
......@@ -11,54 +11,76 @@
from .database import VideoBioFile
from bob.bio.base.database import ZTBioDatabase, BioFile
from bob.bio.base.database import ZTBioDatabase
from bob.bio.video.utils import FrameContainer
import os
import bob.io.base
class YoutubeBioFile(VideoBioFile):
def __init__(self, f):
super(YoutubeBioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id)
self._f = f
def load(self, directory=None, extension='.jpg'):
files = sorted(os.listdir(self.make_path(directory, '')))
fc = FrameContainer()
if extension in (None, '.jpg', '/*.jpg'):
files = sorted(os.listdir(self.make_path(directory, '')))
fc = FrameContainer()
for f in files:
if extension == os.path.splitext(f)[1]:
file_name = os.path.join(self.make_path(directory, ''), f)
fc.add(os.path.basename(file_name), bob.io.base.load(file_name))
return fc
for f in files:
if extension == os.path.splitext(f)[1]:
file_name = os.path.join(self.make_path(directory, ''), f)
fc.add(os.path.basename(file_name), bob.io.base.load(file_name))
return fc
else:
return super(YoutubeBioFile, self).load(directory, extension)
class YoutubeBioDatabase(ZTBioDatabase):
"""
Implements verification API for querying Youtube database.
YOUTUBE database implementation of bob.bio.base.database.ZTDatabase interface.
It is an extension of an SQL-based database interface, which directly talks to YOUTUBE database, for
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
original_extension='/*.jpg',
annotation_extension='.labeled_faces.txt',
**kwargs
):
# call base class constructors to open a session to the database
super(YoutubeBioDatabase, self).__init__(name='youtube',
**kwargs)
super(YoutubeBioDatabase, self).__init__(
name='youtube',
original_directory=original_directory,
original_extension=original_extension,
annotation_extension=annotation_extension,
**kwargs)
from bob.db.youtube.query import Database as LowLevelDatabase
self.__db = LowLevelDatabase()
self._db = LowLevelDatabase(original_directory,
original_extension,
annotation_extension)
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self.__db.model_ids(groups=groups, protocol=protocol)
return self._db.model_ids(groups=groups, protocol=protocol)
def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
return self.__db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
return self._db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
retval = self.__db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)
return [YoutubeBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in retval]
retval = self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)
return [YoutubeBioFile(f) for f in retval]
def tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs):
retval = self.__db.tobjects(groups=groups, protocol=protocol, model_ids=model_ids, **kwargs)
return [YoutubeBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in retval]
retval = self._db.tobjects(groups=groups, protocol=protocol, model_ids=model_ids, **kwargs)
return [YoutubeBioFile(f) for f in retval]
def zobjects(self, groups=None, protocol=None, **kwargs):
retval = self.__db.zobjects(groups=groups, protocol=protocol, **kwargs)
return [YoutubeBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in retval]
retval = self._db.zobjects(groups=groups, protocol=protocol, **kwargs)
return [YoutubeBioFile(f) for f in retval]
def annotations(self, myfile):
return self._db.annotations(myfile._f)
......@@ -28,16 +28,16 @@ class DummyDatabase(ZTBioDatabase):
models_depend_on_protocol=False
)
import bob.db.atnt
self.__db = bob.db.atnt.Database()
self._db = bob.db.atnt.Database()
def _make_bio(self, files):
return [DummyBioFile(client_id=f.client_id, path=f.path, file_id=f.id) for f in files]
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self.__db.model_ids(groups, protocol)
return self._db.model_ids(groups, protocol)
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
return self._make_bio(self.__db.objects(model_ids, groups, purposes, protocol, **kwargs))
return self._make_bio(self._db.objects(model_ids, groups, purposes, protocol, **kwargs))
def tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs):
return []
......@@ -46,7 +46,7 @@ class DummyDatabase(ZTBioDatabase):
return []
def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
return self.__db.model_ids(groups)
return self._db.model_ids(groups)
def t_enroll_files(self, t_model_id, group='dev'):
return self.enroll_files(t_model_id, group)
......@@ -59,4 +59,8 @@ class DummyDatabase(ZTBioDatabase):
files = list(list(zip(*files))[0])
return super(DummyDatabase, self).file_names(files, directory, extension)
def annotations(self, file):
return None
database = DummyDatabase()
......@@ -22,7 +22,8 @@ from nose.plugins.skip import SkipTest
import bob.bio.base
from bob.bio.base.test.utils import db_available
from bob.bio.base.test.test_database_implementations import check_database, check_database_zt
from bob.bio.base.test.test_database_implementations import check_database_zt
from bob.bio.face.test.test_databases import _check_annotations
@db_available('youtube')
......@@ -33,6 +34,12 @@ def test_youtube():
except IOError as e:
raise SkipTest(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
try:
_check_annotations(database, limit_files=1000)
except IOError as e:
raise SkipTest(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
@db_available('mobio')
def test_mobio():
......@@ -42,3 +49,8 @@ def test_mobio():
except IOError as e:
raise SkipTest(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
try:
_check_annotations(database, required=False, limit_files=1000)
except IOError as e:
raise SkipTest(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
......@@ -53,7 +53,7 @@ Hence, when you want to run an experiment using the video wrapper classes, you m
Databases
~~~~~~~~~
All video databases defined here rely on the :py:class:`bob.bio.base.database.BioDatabase` interface, which in turn uses the `verification_databases <https://gitlab.idiap.ch/bob/bob/wikis/Packages>`_.
All video databases defined here rely on the :py:class:`bob.bio.base.database.BioDatabase` interface, which in turn uses the `verification_databases <https://www.idiap.ch/software/bob/packages>`_.
After downloading and extracting the original data of the data sets, it is necessary that the scripts know, where the data was installed.
For this purpose, the ``./bin/verify.py`` script can read a special file, where those directories are stored, see :ref:`bob.bio.base.installation`.
......
......@@ -16,6 +16,14 @@ Summary
bob.bio.video.extractor.Wrapper
bob.bio.video.algorithm.Wrapper
Databases
~~~~~~~~~
.. autosummary::
bob.bio.video.database.MobioBioDatabase
bob.bio.video.database.YoutubeBioDatabase
Details
-------
......
......@@ -48,7 +48,7 @@ setup(
#
# Our database packages are good examples of namespace implementations
# using several layers. You can check them out here:
# https://gitlab.idiap.ch/bob/bob/wikis/Packages
# https://www.idiap.ch/software/bob/packages
# This entry defines which scripts you will have inside the 'bin' directory
......
Supports Markdown
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