Tools implemented in bob.bio.video¶
Summary¶
|
Returns indices of the frames to be selected given the parameters. |
|
A memory efficient class to load only select video frames. |
|
|
Wrapper class to run image preprocessing algorithms on video data. |
|
The base class for video annotators. |
|
|
Annotates video files using the provided image annotator. |
|
A fail-safe video annotator. |
Databases¶
YouTube Faces database implementation of |
Details¶
-
class
bob.bio.video.VideoAsArray(path, selection_style=None, max_number_of_frames=None, step_size=None, transform=None, **kwargs)¶ Bases:
objectA memory efficient class to load only select video frames. It also supports efficient conversion to dask arrays.
-
class
bob.bio.video.VideoLikeContainer(data, indices, **kwargs)¶ Bases:
object-
property
dtype¶
-
property
ndim¶
-
property
shape¶
-
property
-
bob.bio.video.select_frames(count, max_number_of_frames=None, selection_style=None, step_size=None)[source]¶ Returns indices of the frames to be selected given the parameters.
Different selection styles are supported:
first : The first frames are selected
spread : Frames are selected to be taken from the whole video with equal spaces in between.
step : Frames are selected every
step_sizeindices, starting atstep_size/2Think twice if you want to have that when giving FrameContainer data!all : All frames are selected unconditionally.
- Parameters
count (int) – Total number of frames that are available
max_number_of_frames (int) – The maximum number of frames to be selected. Ignored when selection_style is “all”.
selection_style (str) – One of (
first,spread,step,all). See above.step_size (int) – Only useful when
selection_styleisstep.
- Returns
A range of frames to be selected.
- Return type
range
- Raises
ValueError – If
selection_styleis not one of the supported ones.
-
bob.bio.video.annotator.normalize_annotations(annotations, validator, max_age=- 1)[source]¶ Normalizes the annotations of one video sequence. It fills the annotations for frames from previous ones if the annotation for the current frame is not valid.
- Parameters
annotations (collections.OrderedDict) – A dict of dict where the keys to the first dict are frame indices as strings (starting from 0). The inside dicts contain annotations for that frame. The dictionary needs to be an ordered dict in order for this to work.
validator (
callable) – Takes a dict (annotations) and returns True if the annotations are valid. This can be a check based on minimal face size for example: seebob.bio.face.annotator.min_face_size_validator.max_age (
int, optional) – An integer indicating for a how many frames a detected face is valid if no detection occurs after such frame. A value of -1 == forever
- Yields
str – The index of frame.
dict – The corrected annotations of the frame.
-
class
bob.bio.video.annotator.Base[source]¶ Bases:
bob.bio.base.annotator.AnnotatorThe base class for video annotators.
-
static
frame_ids_and_frames(frames)[source]¶ Takes the frames and yields frame_ids and frames.
- Parameters
frames (
bob.bio.video.VideoLikeContainerorbob.bio.video.VideoAsArrayornumpy.array) – The frames of the video file.- Yields
frame_id (str) – A string that represents the frame id.
frame (
numpy.array) – The frame of the video file as an array.
-
annotate(frames, **kwargs)[source]¶ Annotates videos.
- Parameters
frames (
bob.bio.video.VideoLikeContainerorbob.bio.video.VideoAsArrayornumpy.array) – The frames of the video file.**kwargs – Extra arguments that annotators may need.
- Returns
A dictionary where its key is the frame id as a string and its value is a dictionary that are the annotations for that frame.
- Return type
collections.OrderedDict
Note
You can use the
Base.frame_ids_and_framesfunctions to normalize the input in your implementation.
-
transform(samples)[source]¶ Takes a batch of data and annotates them.
Each
kwargsvalue is a list of parameters, with each element of those lists corresponding to each element ofsamples(for example: with[s1, s2, ...]assamples,kwargs['annotations']should contain[{<s1_annotations>}, {<s2_annotations>}, ...]).
-
static
-
class
bob.bio.video.annotator.FailSafeVideo(annotators, max_age=15, validator=None, **kwargs)[source]¶ Bases:
bob.bio.video.annotator.BaseA fail-safe video annotator. It tries several annotators in order and tries the next one if the previous one fails. However, the difference between this annotator and
bob.bio.base.annotator.FailSafeis that this one tries to use annotations from older frames (if valid) before trying the next annotator.Warning
You must be careful in using this annotator since different annotators could have different results. For example the bounding box of one annotator be totally different from another annotator.
- Parameters
annotators (
list) – A list of annotators to try.max_age (int) – The maximum number of frames that an annotation is valid for next frames. This value should be positive. If you want to set max_age to infinite, then you can use the
bob.bio.video.annotator.Wrapperinstead.validator (
callable) – A function that takes the annotations of a frame and validates it.
Please see
Basefor more accepted parameters.-
annotate(frames)[source]¶ See
Base.annotate
-
class
bob.bio.video.annotator.Wrapper(annotator, normalize=False, validator=None, max_age=- 1, **kwargs)[source]¶ Bases:
bob.bio.video.annotator.BaseAnnotates video files using the provided image annotator. See the documentation of
Basetoo.- Parameters
annotator (
bob.bio.base.annotator.Annotatoror str) – The image annotator to be used. The annotator could also be the name of a bob.bio.annotator resource which will be loaded.max_age (int) – see
normalize_annotations.normalize (bool) – If True, it will normalize annotations using
normalize_annotationsvalidator (object) – See
normalize_annotationsandbob.bio.face.annotator.min_face_size_validatorfor one example.
Please see
Basefor more accepted parameters.Warning
You should only set
normalizeto True only if you are annotating all frames of the video file.-
annotate(frames)[source]¶ See
Base.annotate
-
class
bob.bio.video.transformer.VideoWrapper(estimator, **kwargs)[source]¶ Bases:
sklearn.base.TransformerMixin,sklearn.base.BaseEstimatorWrapper class to run image preprocessing algorithms on video data.
Parameters:
- estimatorstr or
sklearn.base.BaseEstimatorinstance The transformer to be used to preprocess the frames.
- estimatorstr or
-
class
bob.bio.video.database.VideoBioFile(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)¶ Bases:
bob.bio.base.database.BioFile-
load()[source]¶ Loads the data at the specified location and using the given extension. Override it if you need to load differently.
- Parameters
original_directory (str (optional)) – The path to the root of the dataset structure. If None, will try to use self.original_directory.
original_extension (str (optional)) – The filename extension of every files in the dataset. If None, will try to use self.original_extension.
- Returns
The loaded data (normally
numpy.ndarray).- Return type
object
-
-
class
bob.bio.video.database.YoutubeBioDatabase(original_directory=None, original_extension='.jpg', annotation_extension='.labeled_faces.txt', **kwargs)¶ Bases:
bob.bio.base.database.ZTBioDatabaseYouTube Faces database implementation of
bob.bio.base.database.ZTBioDatabaseinterface. It is an extension of an SQL-based database interface, which directly talks tobob.db.youtube.Databasedatabase, for verification experiments (good to use inbob.bioframework).-
annotations(myfile)[source]¶ Returns the annotations for the given File object, if available. You need to override this method in your high-level implementation. If your database does not have annotations, it should return
None.Parameters:
- file
bob.bio.base.database.BioFile The file for which annotations should be returned.
Returns:
- annotsdict or None
The annotations for the file, if available.
- file
-
client_id_from_model_id(model_id, group='dev')[source]¶ Return the client id associated with the given model id. In this base class implementation, it is assumed that only one model is enrolled for each client and, thus, client id and model id are identical. All key word arguments are ignored. Please override this function in derived class implementations to change this behavior.
-
model_ids_with_protocol(groups=None, protocol=None, **kwargs) → ids[source]¶ Returns a list of model ids for the given groups and given protocol.
Parameters:
- groupsone or more of
('world', 'dev', 'eval') The groups to get the model ids for.
protocol: a protocol name
Returns:
- ids[int] or [str]
The list of (unique) model ids for the given groups.
- groupsone or more of
-
objects(groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)[source]¶ This function returns a list of
bob.bio.base.database.BioFileobjects or the list of objects which inherit from this class. Returned files fulfill the given restrictions.Keyword parameters:
- groupsstr or [str]
The groups of which the clients should be returned. Usually, groups are one or more elements of (‘world’, ‘dev’, ‘eval’)
- protocol
The protocol for which the clients should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
- purposesstr or [str]
The purposes for which File objects should be retrieved. Usually, purposes are one of (‘enroll’, ‘probe’).
- model_ids[various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
-
property
original_directory¶
-
tmodel_ids_with_protocol(protocol=None, groups=None, **kwargs)[source]¶ This function returns the ids of the T-Norm models of the given groups for the given protocol.
Keyword parameters:
- groupsstr or [str]
The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)
- protocolstr
The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
-
tobjects(groups=None, protocol=None, model_ids=None, **kwargs)[source]¶ This function returns the File objects of the T-Norm models of the given groups for the given protocol and the given model ids.
Keyword parameters:
- groupsstr or [str]
The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)
- protocolstr
The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
- model_ids[various type]
The model ids for which the File objects should be retrieved. What defines a ‘model id’ is dependent on the database. In cases, where there is only one model per client, model ids and client ids are identical. In cases, where there is one model per file, model ids and file ids are identical. But, there might also be other cases.
-
zobjects(groups=None, protocol=None, **kwargs)[source]¶ This function returns the File objects of the Z-Norm impostor files of the given groups for the given protocol.
Keyword parameters:
- groupsstr or [str]
The groups of which the model ids should be returned. Usually, groups are one or more elements of (‘dev’, ‘eval’)
- protocolstr
The protocol for which the model ids should be retrieved. The protocol is dependent on your database. If you do not have protocols defined, just ignore this field.
-