[db] implementing MEDS database in the new interface

parent a8a26357
......@@ -12,13 +12,13 @@ from .multipie import MultipieBioDatabase
from .ijbc import IJBCBioDatabase
from .replaymobile import ReplayMobileBioDatabase
from .fargo import FargoBioDatabase
from .meds import MEDSDatabase
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
"""Says object was actually declared here, and not in the import module.
"""Says object was actually declared here, and not in the import module.
Fixing sphinx warnings of not being able to find classes, when path is shortened.
Parameters:
......@@ -28,20 +28,21 @@ def __appropriate__(*args):
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for obj in args:
obj.__module__ = __name__
for obj in args:
obj.__module__ = __name__
__appropriate__(
FaceBioFile,
MobioBioDatabase,
ReplayBioDatabase,
AtntBioDatabase,
GBUBioDatabase,
ARFaceBioDatabase,
LFWBioDatabase,
MultipieBioDatabase,
IJBCBioDatabase,
ReplayMobileBioDatabase,
FargoBioDatabase
FaceBioFile,
MobioBioDatabase,
ReplayBioDatabase,
AtntBioDatabase,
GBUBioDatabase,
ARFaceBioDatabase,
LFWBioDatabase,
MultipieBioDatabase,
IJBCBioDatabase,
ReplayMobileBioDatabase,
FargoBioDatabase,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
__all__ = [_ for _ in dir() if not _.startswith("_")]
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
"""
MEDS database implementation
"""
from bob.bio.base.database import CSVDatasetDevEval, CSVToSampleLoader
from bob.extension import rc
import bob.io.base
from bob.bio.face.database.sample_loaders import EyesAnnotationsLoader
# TODO: POINT TO THE `.bob/meds``
dataset_protocol_path = "/idiap/user/tpereira/gitlab/bob/bob.nightlies/meds"
class MEDSDatabase(CSVDatasetDevEval):
def __init__(
self,
protocol,
dataset_protocol_path=dataset_protocol_path,
csv_to_sample_loader=CSVToSampleLoader(
data_loader=bob.io.base.load,
metadata_loader=EyesAnnotationsLoader(),
dataset_original_directory=rc["bob.db.meds.directory"],
extension=".jpg",
),
):
# TODO: IMPLEMENT THE DOWNLOAD MECHANISM
super().__init__(dataset_protocol_path, protocol, csv_to_sample_loader)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
""" Sample loader"""
""" Sample and Metatada loader"""
from bob.bio.base.database import CSVToSampleLoader
from bob.pipelines import Sample, DelayedSample, SampleSet
import functools
import os
class CSVToSampleLoaderEyesAnnotations(CSVToSampleLoader):
class EyesAnnotationsLoader:
"""
Convert CSV files in the format below to either a list of
:any:`bob.pipelines.DelayedSample` or :any:`bob.pipelines.SampleSet`
Convert leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
"""
def convert_row_to_sample(self, row, header):
path = row[0]
subject = row[1]
kwargs = dict([[h, r] for h, r in zip(header[2:], row[2:])])
annotations = {
"leye": (kwargs["leye_x"], kwargs["leye_y"]),
"reye": (kwargs["reye_x"], kwargs["reye_y"]),
def __call__(self, row, header=None):
def find_attribute(attribute):
for i, a in enumerate(header):
if a == attribute:
return i
else:
ValueError(f"Attribute not found in the dataset: {a}")
eyes = {
"leye": (row[find_attribute("leye_x")], row[find_attribute("leye_y")]),
"reye": (row[find_attribute("reye_x")], row[find_attribute("reye_y")]),
}
kwargs.pop("leye_x")
kwargs.pop("leye_y")
kwargs.pop("reye_x")
kwargs.pop("reye_y")
return DelayedSample(
functools.partial(
self.data_loader,
os.path.join(self.dataset_original_directory, path + self.extension),
),
key=path,
subject=subject,
annotations=annotations,
**kwargs,
)
"""
class CSVToSampleLoaderEyesAnnotations(CSVToSampleLoader):
def __call__(self, filename):
import ipdb
ipdb.set_trace()
samples = super(CSVToSampleLoaderEyesAnnotations, self).__call__(filename)
def generate_annotations(sample):
Convert leye_x, leye_y, reye_x, reye_y attributes to
`annotations = (leye, reye)`
check_keys = [
a in (sample.__dict__.keys())
for a in ["leye_x", "leye_y", "reye_x", "reye_y"]
]
if not check_keys:
raise ValueError(
"Sample needs to contain the following annotations: 'leye_x', 'leye_y', 'reye_x', 'reye_y'"
)
annotations = {
"leye": (sample.leye_x, sample.leye_y),
"reye": (sample.reye_x, sample.reye_y),
}
# Changing the state of samples for efficiency
# We might have a gigantic amount of datasets
sample.__dict__.pop("leye_x")
sample.__dict__.pop("leye_y")
sample.__dict__.pop("reye_x")
sample.__dict__.pop("reye_y")
sample.annotations = annotations
for sample in samples:
generate_annotations(sample)
annotation = {"annotations": eyes}
return samples
"""
return annotation
This diff is collapsed.
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