Skip to content
Snippets Groups Projects
Commit 75451c07 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Appended the metadata during preprocessing

parent ca797325
No related branches found
No related tags found
1 merge request!125Included metadata during the feature extraction.
...@@ -16,5 +16,14 @@ class DummyPreprocessor (Preprocessor): ...@@ -16,5 +16,14 @@ class DummyPreprocessor (Preprocessor):
return data return data
preprocessor = DummyPreprocessor() preprocessor = DummyPreprocessor()
class DummyPreprocessorMetadata (DummyPreprocessor):
def __call__(self, data, annotation, metadata=None):
"""Does nothing, simply converts the data type of the data, ignoring any annotation."""
assert metadata is not None
return super(DummyPreprocessorMetadata, self).__call__(data, annotation)
preprocessor_metadata = DummyPreprocessorMetadata()
...@@ -148,7 +148,7 @@ def test_verify_resources_metadata(): ...@@ -148,7 +148,7 @@ def test_verify_resources_metadata():
# define dummy parameters # define dummy parameters
parameters = [ parameters = [
'-d', 'dummy', '-d', 'dummy',
'-p', 'dummy', '-p', 'dummy_metadata',
'-e', 'dummy_metadata', '-e', 'dummy_metadata',
'-a', 'dummy', '-a', 'dummy',
'--zt-norm', '--zt-norm',
......
...@@ -2,6 +2,7 @@ import bob.io.base ...@@ -2,6 +2,7 @@ import bob.io.base
import os import os
import logging import logging
import inspect
logger = logging.getLogger("bob.bio.base") logger = logging.getLogger("bob.bio.base")
from .FileSelector import FileSelector from .FileSelector import FileSelector
...@@ -45,6 +46,7 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files ...@@ -45,6 +46,7 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files
data_files = fs.original_data_list(groups=groups) data_files = fs.original_data_list(groups=groups)
original_directory, original_extension = fs.original_directory_and_extension() original_directory, original_extension = fs.original_directory_and_extension()
preprocessed_data_files = fs.preprocessed_data_list(groups=groups) preprocessed_data_files = fs.preprocessed_data_list(groups=groups)
metadata = fs.original_data_list(groups=groups)
# select a subset of keys to iterate # select a subset of keys to iterate
if indices is not None: if indices is not None:
...@@ -58,7 +60,7 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files ...@@ -58,7 +60,7 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files
# read annotation files # read annotation files
annotation_list = fs.annotation_list(groups=groups) annotation_list = fs.annotation_list(groups=groups)
# iterate over the selected files # iterate over the selected files
for i in index_range: for i in index_range:
preprocessed_data_file = preprocessed_data_files[i] preprocessed_data_file = preprocessed_data_files[i]
file_object = data_files[i] file_object = data_files[i]
...@@ -78,7 +80,11 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files ...@@ -78,7 +80,11 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files
annotations = fs.get_annotations(annotation_list[i]) annotations = fs.get_annotations(annotation_list[i])
# call the preprocessor # call the preprocessor
preprocessed_data = preprocessor(data, annotations) if "metadata" in inspect.getargspec(preprocessor.__call__).args:
preprocessed_data = preprocessor(data, annotations, metadata=metadata[i])
else:
preprocessed_data = preprocessor(data, annotations)
if preprocessed_data is None: if preprocessed_data is None:
if allow_missing_files: if allow_missing_files:
logger.debug("... Processing original data file '%s' was not successful", file_name) logger.debug("... Processing original data file '%s' was not successful", file_name)
...@@ -90,8 +96,7 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files ...@@ -90,8 +96,7 @@ def preprocess(preprocessor, groups = None, indices = None, allow_missing_files
preprocessor.write_data(preprocessed_data, preprocessed_data_file) preprocessor.write_data(preprocessed_data, preprocessed_data_file)
else: else:
logger.debug("... Skipping original data file '%s' since preprocessed data '%s' exists", file_name, preprocessed_data_file) logger.debug("... Skipping original data file '%s' since preprocessed data '%s' exists", file_name, preprocessed_data_file)
def read_preprocessed_data(file_names, preprocessor, split_by_client = False, allow_missing_files = False): def read_preprocessed_data(file_names, preprocessor, split_by_client = False, allow_missing_files = False):
......
...@@ -95,6 +95,7 @@ setup( ...@@ -95,6 +95,7 @@ setup(
'bob.bio.preprocessor': [ 'bob.bio.preprocessor': [
'dummy = bob.bio.base.test.dummy.preprocessor:preprocessor', # for test purposes only 'dummy = bob.bio.base.test.dummy.preprocessor:preprocessor', # for test purposes only
'filename = bob.bio.base.config.preprocessor.filename:preprocessor', 'filename = bob.bio.base.config.preprocessor.filename:preprocessor',
'dummy_metadata = bob.bio.base.test.dummy.preprocessor:preprocessor_metadata',
], ],
'bob.bio.extractor': [ 'bob.bio.extractor': [
......
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