Commit aec038f3 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Add back databases, still needs fixes

parent 663e9d4d
Pipeline #45571 failed with stage
in 4 minutes and 26 seconds
from bob.bio.video.database import YoutubeBioDatabase
database = YoutubeBioDatabase(
protocol="fold1",
models_depend_on_protocol=True,
training_depends_on_protocol=True,
all_files_options={"subworld": "fivefolds"},
extractor_training_options={"subworld": "fivefolds"},
projector_training_options={"subworld": "fivefolds"},
enroller_training_options={"subworld": "fivefolds"},
)
from .database import VideoBioFile
from .youtube import YoutubeBioDatabase
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
"""Says object was actually declared here, and not in the import module.
Fixing sphinx warnings of not being able to find classes, when path is shortened.
Parameters:
*args: An iterable of objects to modify
Resolves `Sphinx referencing issues
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for obj in args:
obj.__module__ = __name__
__appropriate__(
VideoBioFile,
YoutubeBioDatabase,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
from bob.bio.base.database.file import BioFile
from ..utils import VideoAsArray
class VideoBioFile(BioFile):
def __init__(
self,
client_id,
path,
file_id,
original_directory=None,
original_extension=".avi",
annotation_directory=None,
annotation_extension=None,
annotation_type=None,
selection_style=None,
max_number_of_frames=None,
step_size=None,
**kwargs,
):
"""
Initializes this File object with an File equivalent for
VoxForge database.
"""
super().__init__(
client_id=client_id,
path=path,
file_id=file_id,
original_directory=original_directory,
original_extension=original_extension,
annotation_directory=annotation_directory,
annotation_extension=annotation_extension,
annotation_type=annotation_type,
**kwargs,
)
self.selection_style = selection_style or "all"
self.max_number_of_frames = max_number_of_frames
self.step_size = step_size
def load(self):
path = self.make_path(self.original_directory, self.original_extension)
return VideoAsArray(
path,
selection_style=self.selection_style,
max_number_of_frames=self.max_number_of_frames,
step_size=self.step_size,
)
"""
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).
"""
import os
import bob.io.base
from bob.bio.base.database import ZTBioDatabase
from bob.extension import rc
from ..utils import VideoLikeContainer
from .database import VideoBioFile
class YoutubeBioFile(VideoBioFile):
def __init__(self, f, **kwargs):
super().__init__(client_id=f.client_id, path=f.path, file_id=f.id, **kwargs)
if self.selection_style != "all":
raise ValueError("Only selection style of 'all' is supported.")
self._f = f
def files(self, directory=None, extension=".jpg"):
base_dir = self.make_path(directory, "")
# collect all files from the data directory
files = [os.path.join(base_dir, f) for f in sorted(os.listdir(base_dir))]
# filter files with the given extension
if extension is not None:
files = [f for f in files if os.path.splitext(f)[1] == extension]
return files
def load(self, directory=None, extension=None, frame_selector=FrameSelector()):
if extension not in (None, ".jpg"):
raise ValueError(f"Unsupported extension {extension}")
data, indices = [], []
files = self.files(directory, extension)
for f in frame_selector(files):
file_name = os.path.join(self.make_path(directory, ""), f[0])
indices.append(os.path.basename(file_name))
data.append(bob.io.base.load(file_name))
return VideoLikeContainer(data=data, indices=indices)
class YoutubeBioDatabase(ZTBioDatabase):
"""
YouTube Faces database implementation of :py:class:`bob.bio.base.database.ZTBioDatabase` interface.
It is an extension of an SQL-based database interface, which directly talks to :py:class:`bob.db.youtube.Database` database, for
verification experiments (good to use in ``bob.bio`` framework).
"""
def __init__(
self,
original_directory=rc["bob.db.youtube.directory"],
original_extension=".jpg",
annotation_extension=".labeled_faces.txt",
**kwargs,
):
from bob.db.youtube.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(
original_directory, original_extension, annotation_extension
)
# call base class constructors to open a session to the database
super(YoutubeBioDatabase, self).__init__(
name="youtube",
original_directory=original_directory,
original_extension=original_extension,
annotation_extension=annotation_extension,
**kwargs,
)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
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)
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(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(f) for f in retval]
def zobjects(self, groups=None, protocol=None, **kwargs):
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)
def client_id_from_model_id(self, model_id, group="dev"):
return self._db.get_client_id_from_file_id(model_id)
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