Skip to content
Snippets Groups Projects
Commit 769aeb47 authored by Amir Mohammadi's avatar Amir Mohammadi Committed by Pavel KORSHUNOV
Browse files

Add support for annotations

parent 9025548f
No related branches found
No related tags found
1 merge request!8Adds annotations for PAD (similar to bob.bio.base)
Pipeline #
......@@ -85,12 +85,24 @@ class PadDatabase(BioDatabase):
"""
return []
@abc.abstractmethod
def annotations(self, file):
"""
Annotations are not supported by PAD interface
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 : :py:class:`bob.pad.base.database.PadFile`
The file for which annotations should be returned.
**Returns:**
annots : dict or None
The annotations for the file, if available.
"""
return None
raise NotImplementedError("This function must be implemented in your derived class.")
@abc.abstractmethod
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
......
......@@ -147,3 +147,10 @@ class FileSelector(object):
no_norm_dir = self.score_directories[0]
return os.path.join(no_norm_dir, "scores-" + group + "-" + obj_type) + self.compressed_extension
def annotation_list(self, groups=None):
"""Returns the list of annotations objects."""
return self.database.all_files(groups=groups)
def get_annotations(self, annotation_file):
"""Returns the annotations of the given file."""
return self.database.annotations(annotation_file)
......@@ -46,6 +46,9 @@ def preprocess(preprocessor, groups=None, indices=None, allow_missing_files=Fals
data_files, original_directory, original_extension = fs.original_data_list_files(groups=groups)
preprocessed_data_files = fs.preprocessed_data_list(groups=groups)
# read annotation files
annotation_list = fs.annotation_list(groups=groups)
# select a subset of keys to iterate
if indices is not None:
index_range = range(indices[0], indices[1])
......@@ -56,6 +59,7 @@ def preprocess(preprocessor, groups=None, indices=None, allow_missing_files=Fals
logger.info("- Preprocessing: processing %d data files from directory '%s' to directory '%s'", len(index_range),
fs.directories['original'], fs.directories['preprocessed'])
# iterate over the selected files
for i in index_range:
preprocessed_data_file = str(preprocessed_data_files[i])
......@@ -69,8 +73,11 @@ def preprocess(preprocessor, groups=None, indices=None, allow_missing_files=Fals
# create output directory before reading the data file (is sometimes required, when relative directories are specified, especially, including a .. somewhere)
bob.io.base.create_directories_safe(os.path.dirname(preprocessed_data_file))
# get the annotations; might be None
annotations = fs.get_annotations(annotation_list[i])
# call the preprocessor
preprocessed_data = preprocessor(data, None)
preprocessed_data = preprocessor(data, annotations)
if preprocessed_data is None:
logger.error("Preprocessing of file '%s' was not successful", file_name)
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment