Commit c9bdae71 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Fix unit tests and clean-up

parent aec038f3
Pipeline #45996 failed with stage
in 2 minutes and 41 seconds
include README.rst bootstrap-buildout.py buildout.cfg develop.cfg COPYING version.txt requirements.txt test-requirements.txt
recursive-include doc *.py *.rst
recursive-include bob/bio/video/test/data *.hdf5 *.avi *.jpg
recursive-include bob/bio/video/test/data *.hdf5 *.avi *.jpg *.txt
......@@ -54,16 +54,6 @@ def normalize_annotations(annotations, validator, max_age=-1):
class Base(bob.bio.base.annotator.Annotator):
"""The base class for video annotators.
Parameters
----------
frame_selector : :any:`bob.bio.video.FrameSelector`
A frame selector class to define, which frames of the video to use.
read_original_data : ``callable``
A function with the signature of
``data = read_original_data(biofile, directory, extension)``
that will be used to load the data from biofiles. By default the
``frame_selector`` is used to load the data.
"""
@staticmethod
......@@ -72,7 +62,7 @@ class Base(bob.bio.base.annotator.Annotator):
Parameters
----------
frames : :any:`bob.bio.video.FrameContainer` or an iterable of arrays
frames : :any:`bob.bio.video.VideoLikeContainer` or :any:`bob.bio.video.VideoAsArray` or :any:`numpy.array`
The frames of the video file.
Yields
......@@ -82,8 +72,8 @@ class Base(bob.bio.base.annotator.Annotator):
frame : :any:`numpy.array`
The frame of the video file as an array.
"""
if isinstance(frames, utils.FrameContainer):
for fid, fr, _ in frames:
if isinstance(frames, (utils.VideoAsArray, utils.VideoLikeContainer)):
for fid, fr in zip(frames.indices, frames):
yield fid, fr
else:
for fid, fr in enumerate(frames):
......@@ -94,7 +84,7 @@ class Base(bob.bio.base.annotator.Annotator):
Parameters
----------
frames : :any:`bob.bio.video.FrameContainer` or :any:`numpy.array`
frames : :any:`bob.bio.video.VideoLikeContainer` or :any:`bob.bio.video.VideoAsArray` or :any:`numpy.array`
The frames of the video file.
**kwargs
Extra arguments that annotators may need.
......@@ -113,6 +103,16 @@ class Base(bob.bio.base.annotator.Annotator):
"""
raise NotImplementedError()
def transform(self, samples):
"""Takes a batch of data and annotates them.
Each ``kwargs`` value is a list of parameters, with each element of those
lists corresponding to each element of ``samples`` (for example:
with ``[s1, s2, ...]`` as ``samples``, ``kwargs['annotations']``
should contain ``[{<s1_annotations>}, {<s2_annotations>}, ...]``).
"""
return [self.annotate(sample) for sample in samples]
class FailSafeVideo(Base):
"""A fail-safe video annotator.
......@@ -146,27 +146,36 @@ class FailSafeVideo(Base):
self,
annotators,
max_age=15,
validator=bob.bio.face.annotator.min_face_size_validator,
validator=None,
**kwargs,
):
super().__init__(**kwargs)
assert max_age > 0, "max_age: `{}' cannot be less than 1".format(max_age)
if max_age <= 0:
raise ValueError(
f"max_age: `{max_age}' cannot be less than 1, If you want to set max_age to infinite,"
"then you can use the :any:`bob.bio.video.annotator.Wrapper` with `normalize` set to True."
)
self.max_age = max_age
if validator is None:
validator = bob.bio.face.annotator.min_face_size_validator
self.validator = validator
self.annotators = []
for annotator in annotators:
if isinstance(annotator, str):
annotator = bob.bio.base.load_resource(annotator, "annotator")
self.annotators.append(annotator)
self.max_age = max_age
self.validator = validator
def annotate(self, frames, **kwargs):
def annotate(self, frames):
"""See :any:`Base.annotate`"""
annotations = collections.OrderedDict()
video_annotations = collections.OrderedDict()
current = None
age = 0
for i, frame in self.frame_ids_and_frames(frames):
for annotator in self.annotators:
annot = annotator.annotate(frame, **kwargs)
annot = annotator.transform([frame])[0]
if annot and self.validator(annot):
current = annot
age = 0
......@@ -180,8 +189,8 @@ class FailSafeVideo(Base):
if current is not annot:
logger.debug("Annotator `%s' failed.", annotator)
annotations[i] = current
return annotations
video_annotations[i] = current
return video_annotations
class Wrapper(Base):
......@@ -215,7 +224,7 @@ class Wrapper(Base):
self,
annotator,
normalize=False,
validator=bob.bio.face.annotator.min_face_size_validator,
validator=None,
max_age=-1,
**kwargs,
):
......@@ -225,16 +234,20 @@ class Wrapper(Base):
if isinstance(annotator, str):
annotator = bob.bio.base.load_resource(annotator, "annotator")
self.annotator = annotator
self.normalize = normalize
if validator is None:
validator = bob.bio.face.annotator.min_face_size_validator
self.validator = validator
self.normalize = normalize
self.max_age = max_age
def annotate(self, frames, **kwargs):
def annotate(self, frames):
"""See :any:`Base.annotate`"""
annotations = collections.OrderedDict()
for i, frame in self.frame_ids_and_frames(frames):
logger.debug("Annotating frame %s", i)
annotations[i] = self.annotator(frame, **kwargs)
annotations[i] = self.annotator.transform([frame])[0]
if self.normalize:
annotations = collections.OrderedDict(
normalize_annotations(annotations, self.validator, self.max_age)
......
from bob.bio.base.pipelines.vanilla_biometrics.legacy import DatabaseConnector
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"},
database = DatabaseConnector(
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"},
)
)
......@@ -11,33 +11,38 @@ import bob.io.base
from bob.bio.base.database import ZTBioDatabase
from bob.extension import rc
from ..utils import VideoLikeContainer
from ..utils import VideoLikeContainer, select_frames
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, "")
def files(self):
base_dir = self.make_path(self.original_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]
if self.original_extension is not None:
files = [
f for f in files if os.path.splitext(f)[1] == self.original_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}")
def load(self, *args, **kwargs):
files = self.files()
files_indices = select_frames(
len(files),
max_number_of_frames=self.max_number_of_frames,
selection_style=self.selection_style,
step_size=self.step_size,
)
data, indices = [], []
files = self.files(directory, extension)
for f in frame_selector(files):
file_name = os.path.join(self.make_path(directory, ""), f[0])
for i, file_name in enumerate(files):
if i not in files_indices:
continue
indices.append(os.path.basename(file_name))
data.append(bob.io.base.load(file_name))
return VideoLikeContainer(data=data, indices=indices)
......@@ -86,6 +91,13 @@ class YoutubeBioDatabase(ZTBioDatabase):
def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
return self._db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
def _populate_files_attrs(self, files):
for f in files:
f.original_directory = self.original_directory
f.original_extension = self.original_extension
f.annotation_extension = self.annotation_extension
return files
def objects(
self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs
):
......@@ -96,17 +108,17 @@ class YoutubeBioDatabase(ZTBioDatabase):
model_ids=model_ids,
**kwargs,
)
return [YoutubeBioFile(f) for f in retval]
return self._populate_files_attrs([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]
return self._populate_files_attrs([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]
return self._populate_files_attrs([YoutubeBioFile(f) for f in retval])
def annotations(self, myfile):
return self._db.annotations(myfile._f)
......
Aaron_Eckhart\0\0.555.jpg,0,237,137,84,84,0.0,1
Aaron_Eckhart\0\0.556.jpg,0,235,136,85,85,0.0,1
Aaron_Eckhart\0\0.557.jpg,0,233,134,86,86,0.0,1
Aaron_Eckhart\0\0.558.jpg,0,231,130,88,88,0.0,1
Aaron_Eckhart\0\0.559.jpg,0,229,128,88,88,0.0,1
Aaron_Eckhart\0\0.560.jpg,0,227,124,89,89,0.0,1
Aaron_Eckhart\0\0.561.jpg,0,224,121,87,87,0.0,1
Aaron_Eckhart\0\0.562.jpg,0,219,116,85,85,0.0,1
Aaron_Eckhart\0\0.563.jpg,0,217,114,87,87,0.0,1
Aaron_Eckhart\0\0.564.jpg,0,215,112,84,84,0.0,1
Aaron_Eckhart\0\0.565.jpg,0,212,110,85,85,0.0,1
Aaron_Eckhart\0\0.566.jpg,0,209,109,82,82,0.0,1
Aaron_Eckhart\0\0.567.jpg,0,207,108,81,81,0.0,1
Aaron_Eckhart\0\0.568.jpg,0,207,109,82,82,0.0,1
Aaron_Eckhart\0\0.569.jpg,0,206,109,82,82,0.0,1
Aaron_Eckhart\0\0.570.jpg,0,204,111,81,81,0.0,1
Aaron_Eckhart\0\0.571.jpg,0,206,112,82,82,0.0,1
Aaron_Eckhart\0\0.572.jpg,0,206,111,83,83,0.0,1
Aaron_Eckhart\0\0.573.jpg,0,207,111,83,83,0.0,1
Aaron_Eckhart\0\0.574.jpg,0,208,112,85,85,0.0,1
Aaron_Eckhart\0\0.575.jpg,0,209,112,84,84,0.0,1
Aaron_Eckhart\0\0.576.jpg,0,209,112,85,85,0.0,1
Aaron_Eckhart\0\0.577.jpg,0,212,112,84,84,0.0,1
Aaron_Eckhart\0\0.578.jpg,0,213,112,85,85,0.0,1
Aaron_Eckhart\0\0.579.jpg,0,216,111,85,85,0.0,1
Aaron_Eckhart\0\0.580.jpg,0,217,112,84,84,0.0,1
Aaron_Eckhart\0\0.581.jpg,0,219,111,85,85,0.0,1
Aaron_Eckhart\0\0.582.jpg,0,222,111,86,86,0.0,1
Aaron_Eckhart\0\0.583.jpg,0,223,110,85,85,0.0,1
Aaron_Eckhart\0\0.584.jpg,0,225,110,85,85,0.0,1
Aaron_Eckhart\0\0.585.jpg,0,224,110,85,85,0.0,1
Aaron_Eckhart\0\0.586.jpg,0,224,110,87,87,0.0,1
Aaron_Eckhart\0\0.587.jpg,0,225,110,84,84,0.0,1
Aaron_Eckhart\0\0.588.jpg,0,225,110,85,85,0.0,1
Aaron_Eckhart\0\0.589.jpg,0,226,110,84,84,0.0,1
Aaron_Eckhart\0\0.590.jpg,0,227,110,86,86,0.0,1
Aaron_Eckhart\0\0.591.jpg,0,227,110,84,84,0.0,1
Aaron_Eckhart\0\0.592.jpg,0,230,109,86,86,0.0,1
Aaron_Eckhart\0\0.593.jpg,0,232,107,85,85,0.0,1
Aaron_Eckhart\0\0.594.jpg,0,240,106,84,84,0.0,1
Aaron_Eckhart\0\0.595.jpg,0,243,105,87,87,0.0,1
Aaron_Eckhart\0\0.596.jpg,0,248,105,88,88,0.0,1
Aaron_Eckhart\0\0.597.jpg,0,255,104,87,87,0.0,1
Aaron_Eckhart\0\0.598.jpg,0,256,104,84,84,0.0,1
Aaron_Eckhart\0\0.599.jpg,0,261,103,86,86,0.0,1
Aaron_Eckhart\0\0.600.jpg,0,262,102,83,83,0.0,1
Aaron_Eckhart\0\0.601.jpg,0,263,102,85,85,0.0,1
Aaron_Eckhart\0\0.602.jpg,0,266,103,86,86,0.0,1
Aaron_Eckhart\0\0.603.jpg,0,265,104,84,84,0.0,1
Aaron_Eckhart\0\0.604.jpg,0,268,103,86,86,0.0,1
Aaron_Eckhart\0\0.605.jpg,0,265,103,83,83,0.0,1
Aaron_Eckhart\0\0.606.jpg,0,264,103,85,85,0.0,1
Aaron_Eckhart\0\0.607.jpg,0,264,103,83,83,0.0,1
Aaron_Eckhart\0\0.608.jpg,0,264,103,82,82,0.0,1
Aaron_Eckhart\0\0.609.jpg,0,259,103,89,89,0.0,1
Aaron_Eckhart\0\0.610.jpg,0,259,103,85,85,0.0,1
Aaron_Eckhart\0\0.611.jpg,0,260,103,87,87,0.0,1
Aaron_Eckhart\0\0.612.jpg,0,259,104,86,86,0.0,1
Aaron_Eckhart\0\0.613.jpg,0,259,104,86,86,0.0,1
Aaron_Eckhart\0\0.614.jpg,0,257,104,85,85,0.0,1
Aaron_Eckhart\0\0.615.jpg,0,256,105,86,86,0.0,1
Aaron_Eckhart\0\0.616.jpg,0,258,105,87,87,0.0,1
Aaron_Eckhart\0\0.617.jpg,0,256,106,86,86,0.0,1
Aaron_Eckhart\0\0.618.jpg,0,255,106,88,88,0.0,1
Aaron_Eckhart\0\0.619.jpg,0,254,106,86,86,0.0,1
Aaron_Eckhart\0\0.620.jpg,0,254,106,86,86,0.0,1
Aaron_Eckhart\0\0.621.jpg,0,257,105,83,83,0.0,1
Aaron_Eckhart\0\0.622.jpg,0,257,106,83,83,0.0,1
Aaron_Eckhart\0\0.623.jpg,0,256,108,89,89,0.0,1
Aaron_Eckhart\0\0.624.jpg,0,259,108,87,87,0.0,1
Aaron_Eckhart\0\0.625.jpg,0,261,108,88,88,0.0,1
Aaron_Eckhart\0\0.626.jpg,0,260,109,88,88,0.0,1
Aaron_Eckhart\0\0.627.jpg,0,261,108,86,86,0.0,1
Aaron_Eckhart\0\0.628.jpg,0,257,108,88,88,0.0,1
Aaron_Eckhart\0\0.629.jpg,0,261,108,86,86,0.0,1
Aaron_Eckhart\0\0.630.jpg,0,256,109,86,86,0.0,1
Aaron_Eckhart\0\0.631.jpg,0,261,109,86,86,0.0,1
Aaron_Eckhart\0\0.632.jpg,0,257,109,86,86,0.0,1
Aaron_Eckhart\0\0.633.jpg,0,257,108,85,85,0.0,1
Aaron_Eckhart\0\0.634.jpg,0,258,108,90,90,0.0,1
Aaron_Eckhart\0\0.635.jpg,0,258,109,92,92,0.0,1
Aaron_Eckhart\0\0.636.jpg,0,260,108,92,92,0.0,1
Aaron_Eckhart\0\0.637.jpg,0,259,108,89,89,0.0,1
Aaron_Eckhart\0\0.638.jpg,0,260,108,89,89,0.0,1
Aaron_Eckhart\0\0.639.jpg,0,263,109,91,91,0.0,1
Aaron_Eckhart\1\1.183.jpg,0,170,84,83,83,0.0,1
Aaron_Eckhart\1\1.184.jpg,0,169,85,83,83,0.0,1
Aaron_Eckhart\1\1.185.jpg,0,171,85,82,82,0.0,1
Aaron_Eckhart\1\1.186.jpg,0,170,86,83,83,0.0,1
Aaron_Eckhart\1\1.187.jpg,0,170,88,84,84,0.0,1
Aaron_Eckhart\1\1.188.jpg,0,169,86,83,83,0.0,1
Aaron_Eckhart\1\1.189.jpg,0,170,87,82,82,0.0,1
Aaron_Eckhart\1\1.190.jpg,0,168,87,85,85,0.0,1
Aaron_Eckhart\1\1.191.jpg,0,169,86,82,82,0.0,1
Aaron_Eckhart\1\1.192.jpg,0,167,86,85,85,0.0,1
Aaron_Eckhart\1\1.193.jpg,0,167,85,84,84,0.0,1
Aaron_Eckhart\1\1.194.jpg,0,167,85,84,84,0.0,1
Aaron_Eckhart\1\1.195.jpg,0,167,83,83,83,0.0,1
Aaron_Eckhart\1\1.196.jpg,0,167,83,87,87,0.0,1
Aaron_Eckhart\1\1.197.jpg,0,167,83,86,86,0.0,1
Aaron_Eckhart\1\1.198.jpg,0,168,83,84,84,0.0,1
Aaron_Eckhart\1\1.199.jpg,0,168,82,83,83,0.0,1
Aaron_Eckhart\1\1.200.jpg,0,170,84,84,84,0.0,1
Aaron_Eckhart\1\1.201.jpg,0,169,85,84,84,0.0,1
Aaron_Eckhart\1\1.202.jpg,0,169,85,84,84,0.0,1
Aaron_Eckhart\1\1.203.jpg,0,170,86,85,85,0.0,1
Aaron_Eckhart\1\1.204.jpg,0,169,87,84,84,0.0,1
Aaron_Eckhart\1\1.205.jpg,0,172,88,84,84,0.0,1
Aaron_Eckhart\1\1.206.jpg,0,172,87,84,84,0.0,1
Aaron_Eckhart\1\1.207.jpg,0,172,87,83,83,0.0,1
Aaron_Eckhart\1\1.208.jpg,0,171,87,86,86,0.0,1
Aaron_Eckhart\1\1.209.jpg,0,171,86,83,83,0.0,1
Aaron_Eckhart\1\1.210.jpg,0,171,84,84,84,0.0,1
Aaron_Eckhart\1\1.211.jpg,0,171,83,83,83,0.0,1
Aaron_Eckhart\1\1.212.jpg,0,170,83,85,85,0.0,1
Aaron_Eckhart\1\1.213.jpg,1,170,83,86,86,0.0,1
Aaron_Eckhart\1\1.214.jpg,0,170,81,85,85,0.0,1
Aaron_Eckhart\1\1.215.jpg,0,170,82,88,88,0.0,1
Aaron_Eckhart\1\1.216.jpg,1,169,82,86,86,0.0,1
Aaron_Eckhart\1\1.217.jpg,0,168,81,83,83,0.0,1
Aaron_Eckhart\1\1.218.jpg,0,169,82,83,83,0.0,1
Aaron_Eckhart\1\1.219.jpg,0,169,83,85,85,0.0,1
Aaron_Eckhart\1\1.220.jpg,0,169,84,83,83,0.0,1
Aaron_Eckhart\1\1.221.jpg,0,170,87,84,84,0.0,1
Aaron_Eckhart\1\1.222.jpg,0,169,86,85,85,0.0,1
Aaron_Eckhart\1\1.223.jpg,0,169,87,83,83,0.0,1
Aaron_Eckhart\1\1.224.jpg,0,170,88,84,84,0.0,1
Aaron_Eckhart\1\1.225.jpg,0,169,87,83,83,0.0,1
Aaron_Eckhart\1\1.226.jpg,0,169,88,85,85,0.0,1
Aaron_Eckhart\1\1.227.jpg,0,168,88,88,88,0.0,1
Aaron_Eckhart\1\1.228.jpg,0,170,87,85,85,0.0,1
Aaron_Eckhart\1\1.229.jpg,0,170,87,86,86,0.0,1
Aaron_Eckhart\1\1.230.jpg,0,169,86,83,83,0.0,1
Aaron_Eckhart\1\1.231.jpg,0,169,87,86,86,0.0,1
Aaron_Eckhart\2\2.1718.jpg,0,165,80,35,35,0.0,1
Aaron_Eckhart\2\2.1719.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1720.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1721.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1722.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1723.jpg,0,164,79,31,31,0.0,1
Aaron_Eckhart\2\2.1724.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1725.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1726.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1727.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1728.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1729.jpg,0,164,80,33,33,0.0,1
Aaron_Eckhart\2\2.1730.jpg,0,165,80,32,32,0.0,1
Aaron_Eckhart\2\2.1731.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1732.jpg,0,165,80,32,32,0.0,1
Aaron_Eckhart\2\2.1733.jpg,0,163,80,33,33,0.0,1
Aaron_Eckhart\2\2.1734.jpg,0,163,80,33,33,0.0,1
Aaron_Eckhart\2\2.1735.jpg,0,163,80,33,33,0.0,1
Aaron_Eckhart\2\2.1736.jpg,0,163,80,33,33,0.0,1
Aaron_Eckhart\2\2.1737.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1738.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1739.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1740.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1741.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1742.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1743.jpg,0,164,80,34,34,0.0,1
Aaron_Eckhart\2\2.1744.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1745.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1746.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1747.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1748.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1749.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1750.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1751.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1752.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1753.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1754.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1755.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1756.jpg,0,165,80,32,32,0.0,1
Aaron_Eckhart\2\2.1757.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1758.jpg,0,163,80,31,31,0.0,1
Aaron_Eckhart\2\2.1759.jpg,0,163,80,31,31,0.0,1
Aaron_Eckhart\2\2.1760.jpg,0,164,80,31,31,0.0,1
Aaron_Eckhart\2\2.1761.jpg,0,163,80,31,31,0.0,1
Aaron_Eckhart\2\2.1762.jpg,0,163,80,31,31,0.0,1
Aaron_Eckhart\2\2.1763.jpg,0,163,80,31,31,0.0,1
Aaron_Eckhart\2\2.1764.jpg,0,163,80,31,31,0.0,1
Aaron_Eckhart\2\2.1765.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1766.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1767.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1768.jpg,0,164,80,32,32,0.0,1
Aaron_Eckhart\2\2.1769.jpg,0,164,80,33,33,0.0,1
Aaron_Eckhart\2\2.1770.jpg,0,164,80,33,33,0.0,1
Aaron_Eckhart\2\2.1771.jpg,0,164,80,33,33,0.0,1
Aaron_Eckhart\2\2.1772.jpg,0,164,80,33,33,0.0,1
Aaron_Eckhart\2\2.1773.jpg,0,164,80,33,33,0.0,1
from bob.bio.base.database import ZTBioDatabase
from bob.bio.base.test.utils import atnt_database_directory
from bob.bio.base.database.file import BioFile
from bob.bio.video.database import VideoBioFile
from bob.bio.video.utils import FrameContainer
from bob.bio.video import VideoLikeContainer
import bob.io.base
import os
class DummyBioFile(VideoBioFile):
def load(self, directory=None, extension='.pgm', frame_selector=None):
file_name = self.make_path(directory, extension)
fc = FrameContainer()
fc.add(os.path.basename(file_name), bob.io.base.load(file_name))
def load(self):
file_name = self.make_path(self.original_directory, self.original_extension)
fc = VideoLikeContainer([bob.io.base.load(file_name)], [os.path.basename(file_name)])
return fc
......
......@@ -10,91 +10,98 @@ from bob.bio.face.test.test_annotators import _assert_bob_ip_facedetect
class FailSucessAnnotator(bob.bio.base.annotator.Annotator):
"""An annotator that fails for every second time it is called."""
"""An annotator that fails for every second time it is called."""
def __init__(self, **kwargs):
super(FailSucessAnnotator, self).__init__(**kwargs)
self.failed_last_time = True
def __init__(self, **kwargs):
super(FailSucessAnnotator, self).__init__(**kwargs)
self.failed_last_time = True
def annotate(self, image, **kwargs):
if not self.failed_last_time:
self.failed_last_time = True
return None
else:
self.failed_last_time = False
return {
'topleft': (0, 0),
'bottomright': (64, 64)
}
def annotate(self, image, **kwargs):
if not self.failed_last_time:
self.failed_last_time = True
return None
else:
self.failed_last_time = False
return {"topleft": (0, 0), "bottomright": (64, 64)}
def transform(self, images):
return [self.annotate(img) for img in images]
def test_wrapper():
original_path = pkg_resources.resource_filename("bob.bio.face.test", "")
image_files = DummyBioFile(client_id=1, file_id=1, path="data/testimage")
def test_wrapper():
# video preprocessor using a face crop preprocessor
annotator = bob.bio.video.annotator.Wrapper('facedetect')
original_path = pkg_resources.resource_filename("bob.bio.face.test", "")
image_files = DummyBioFile(
client_id=1,
file_id=1,
path="data/testimage",
original_directory=original_path,
original_extension=".jpg",
)
# read original data
original = image_files.load()
# video preprocessor using a face crop preprocessor
annotator = bob.bio.video.annotator.Wrapper("facedetect")
assert isinstance(original, bob.bio.video.VideoLikeContainer)
assert len(original) == 1
assert original.indices[0] == os.path.basename(
image_files.make_path(original_path, ".jpg")
)
# annotate data
annot = annotator.transform([original])[0]
assert isinstance(annot, collections.OrderedDict), annot
_assert_bob_ip_facedetect(annot["testimage.jpg"])
def _get_test_video():
original_path = pkg_resources.resource_filename("bob.bio.video.test", "")
# here I am using 3 frames to test normalize but in real applications this
# should not be done.
video_object = bob.bio.video.database.VideoBioFile(
client_id=1,
file_id=1,
path="data/testvideo",
original_directory=original_path,
original_extension=".avi",
max_number_of_frames=3,
selection_style="spread",
)
video = video_object.load()
assert isinstance(video, bob.bio.video.VideoAsArray)
return video
# read original data
original = annotator.read_original_data(
image_files, original_path, ".jpg")
assert isinstance(original, bob.bio.video.FrameContainer)
assert len(original) == 1
assert original[0][0] == os.path.basename(
image_files.make_path(original_path, ".jpg"))
def test_wrapper_normalize():
# annotate data
annot = annotator(original)
video = _get_test_video()
assert isinstance(annot, collections.OrderedDict), annot
_assert_bob_ip_facedetect(annot['testimage.jpg'])
annotator = bob.bio.video.annotator.Wrapper("flandmark", normalize=True)
annot = annotator.transform([video])[0]
def test_wrapper_normalize():
# check if annotations are ordered by frame number
assert list(annot.keys()) == sorted(annot.keys(), key=int), annot
original_path = pkg_resources.resource_filename("bob.bio.video.test", "")
video_object = bob.bio.video.database.VideoBioFile(
client_id=1, file_id=1, path="data/testvideo")
# here I am using 3 frames to test normalize but in real applications this
# should not be done.
frame_selector = bob.bio.video.FrameSelector(
max_number_of_frames=3, selection_style="spread")
annotator = bob.bio.video.annotator.Wrapper(
'flandmark', frame_selector=frame_selector, normalize=True)
video = annotator.read_original_data(video_object, original_path, ".avi")
assert isinstance(video, bob.bio.video.FrameContainer)
def test_failsafe_video():
annot = annotator(video)
video = _get_test_video()
# check if annotations are ordered by frame number
assert list(annot.keys()) == sorted(annot.keys(), key=int), annot
annotator = bob.bio.video.annotator.FailSafeVideo(
[FailSucessAnnotator(), "facedetect"]
)
annot = annotator.transform(video)[0]
def test_failsafe_video():
# check if annotations are ordered by frame number
assert list(annot.keys()) == sorted(annot.keys(), key=int), annot
original_path = pkg_resources.resource_filename("bob.bio.video.test", "")
video_object = bob.bio.video.database.VideoBioFile(
client_id=1, file_id=1, path="data/testvideo")
# here I am using 3 frames to test normalize but in real applications this
# should not be done.
frame_selector = bob.bio.video.FrameSelector(
max_number_of_frames=3, selection_style="spread")
annotator = bob.bio.video.annotator.FailSafeVideo(
[FailSucessAnnotator(), 'facedetect'], frame_selector=frame_selector)
video = annotator.read_original_data(video_object, original_path, ".avi")
assert isinstance(video, bob.bio.video.FrameContainer)
annot = annotator(video)
# check if annotations are ordered by frame number
assert list(annot.keys()) == sorted(annot.keys(), key=int), annot
# check if the failsuccess annotator was used for all frames
for _, annotations in annot.items():
assert 'topleft' in annotations, annot
assert annotations['topleft'] == (0, 0), annot
assert annotations['bottomright'] == (64, 64), annot
# check if the failsuccess annotator was used for all frames
for _, annotations in annot.items():
assert "topleft" in annotations, annot
assert annotations["topleft"] == (0, 0), annot
assert annotations["bottomright"] == (64, 64), annot
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_zt
from bob.bio.face.test.test_databases import _check_annotations
import pkg_resources
@db_available("youtube")
def test_youtube():
database = bob.bio.base.load_resource(
"youtube", "database", preferred_package="bob.bio.video"
)
try:
check_database_zt(database, training_depends=True, models_depend=True)
except IOError as e:
raise SkipTest(
"The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e
)
try:
_check_annotations(database, limit_files=1000, topleft=True, framed=True)
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("youtube")
def test_youtube_load_method():
database = bob.bio.base.load_resource(
"youtube", "database", preferred_package="bob.bio.video"
)
database.database.original_directory = pkg_resources.resource_filename(
"bob.bio.video", "test/data"
)
youtube_db_sample = [