Commit c4530ae7 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

Validators should handle empty annotations too

removed conversion of ids to strings.
Improved documentation
parent e627bfc7
Pipeline #17677 failed with stage
in 19 minutes and 4 seconds
......@@ -29,7 +29,7 @@ class Base(bob.bio.base.annotator.Annotator):
super(Base, self).__init__(read_original_data=read_original_data, **kwargs)
@staticmethod
def frame_and_frame_ids(frames):
def frame_ids_and_frames(frames):
"""Normalizes the frames parameter into a numpy array and a list of
indices.
......@@ -40,10 +40,10 @@ class Base(bob.bio.base.annotator.Annotator):
Returns
-------
frames : :any:`numpy.array`
The frames of the video file as a numpy array.
frame_ids : list
A list of strings that represent the frame ids.
frames : :any:`numpy.array`
The frames of the video file as a numpy array.
"""
if isinstance(frames, utils.FrameContainer):
frame_ids = [fid for fid, _, _ in frames]
......@@ -51,7 +51,7 @@ class Base(bob.bio.base.annotator.Annotator):
else: # frames is already a numpy.array
frame_ids = [str(i) for i in range(len(frames))]
return frames, frame_ids
return frame_ids, frames
def annotate(self, frames, **kwargs):
"""Annotates videos.
......@@ -72,7 +72,7 @@ class Base(bob.bio.base.annotator.Annotator):
.. note::
You can use the :any:`Base.frame_and_frame_ids` functions to normalize
You can use the :any:`Base.frame_ids_and_frames` functions to normalize
the input in your implementation.
"""
raise NotImplementedError()
......@@ -20,7 +20,7 @@ class FailSafeVideo(Base):
could have different results. For example the bounding box of one
annotator be totally different from another annotator.
Attributes
Parameters
----------
annotators : list
A list of annotators to try.
......@@ -30,6 +30,9 @@ class FailSafeVideo(Base):
then you can use the :any:`bob.bio.video.annotator.Wrapper` instead.
validator : callable
A function that takes the annotations of a frame and validates it.
Please see :any:`Base` for more accepted parameters.
"""
def __init__(self, annotators, max_age=15,
......@@ -48,7 +51,7 @@ class FailSafeVideo(Base):
def annotate(self, frames, **kwargs):
"""See :any:`Base.annotate`
"""
frames, frame_ids = self.frame_and_frame_ids(frames)
frame_ids, frames = self.frame_ids_and_frames(frames)
annotations = collections.OrderedDict()
current = None
age = 0
......@@ -68,5 +71,5 @@ class FailSafeVideo(Base):
if current is not annot:
logger.debug("Annotator `%s' failed.", annotator)
annotations[str(i)] = current
annotations[i] = current
return annotations
......@@ -23,6 +23,8 @@ class Wrapper(Base):
:any:`bob.bio.face.annotator.min_face_size_validator` for one example.
Please see :any:`Base` for more accepted parameters.
.. warning::
You should only set ``normalize`` to True only if you are annotating
......@@ -50,10 +52,10 @@ class Wrapper(Base):
def annotate(self, frames, **kwargs):
"""See :any:`Base.annotate`
"""
frames, frame_ids = self.frame_and_frame_ids(frames)
frame_ids, frames = self.frame_ids_and_frames(frames)
annotations = collections.OrderedDict()
for i, frame in zip(frame_ids, frames):
annotations[str(i)] = self.annotator(frame, **kwargs)
annotations[i] = self.annotator(frame, **kwargs)
if self.normalize:
annotations = collections.OrderedDict(normalize_annotations(
annotations, self.validator, self.max_age))
......
......@@ -30,7 +30,7 @@ def normalize_annotations(annotations, validator, max_age=-1):
age = 0
for k, annot in annotations.items():
if annot and validator(annot):
if validator(annot):
current = annot
age = 0
elif max_age < 0 or age < max_age:
......
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