Created interface for MEDS dataset

Updated database interface

[meds] Finished interface
parent bd592d5a
......@@ -44,5 +44,6 @@ __appropriate__(
IJBCBioDatabase,
ReplayMobileBioDatabase,
FargoBioDatabase,
MEDSDatabase,
)
__all__ = [_ for _ in dir() if not _.startswith("_")]
......@@ -6,30 +6,63 @@
MEDS database implementation
"""
from bob.bio.base.database import CSVDatasetDevEval, CSVToSampleLoader
from bob.bio.base.database import (
CSVDatasetDevEval,
CSVDatasetDevEvalZTNorm,
CSVToSampleLoader,
)
from bob.extension import rc
from bob.extension.download import get_file
import bob.io.base
from bob.bio.face.database.sample_loaders import EyesAnnotationsLoader
from bob.bio.face.database.sample_loaders import eyes_annotations_loader
import os
# TODO: POINT TO THE `.bob/meds``
dataset_protocol_path = "/idiap/user/tpereira/gitlab/bob/bob.nightlies/meds"
cache_subdir = "datasets"
filename = "meds.tar.gz"
dataset_protocol_path = os.path.join(
os.path.expanduser("~"), "bob_data", cache_subdir, filename
)
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",
),
):
class MEDSDatabase(CSVDatasetDevEvalZTNorm):
"""
The MEDS-II (Multiple Encounter Data Set II) database interface
# TODO: IMPLEMENT THE DOWNLOAD MECHANISM
.. warning::
Use the command below to set the path of the real data::
super().__init__(dataset_protocol_path, protocol, csv_to_sample_loader)
$ bob config set bob.db.meds.directory [PATH-TO-MEDS-DATA]
Parameters
----------
protocol: str
One of the database protocols. Options are `verification_fold1`, `verification_fold2` and `verification_fold3`
"""
def __init__(self, protocol):
# Downloading model if not exists
urls = [
"https://www.idiap.ch/software/bob/databases/latest/meds.tar.gz",
"http://www.idiap.ch/software/bob/databases/latest/meds.tar.gz",
]
get_file(filename, urls)
self.annotation_type = ("eyes-center",)
self.fixed_positions = None
database = CSVDatasetDevEval(
dataset_protocol_path,
protocol,
csv_to_sample_loader=CSVToSampleLoader(
data_loader=bob.io.base.load,
metadata_loader=eyes_annotations_loader,
dataset_original_directory=rc["bob.db.meds.directory"],
extension=".jpg",
),
)
super().__init__(database)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
""" Sample and Metatada loader"""
""" Sample and Metatada loaders"""
class EyesAnnotationsLoader:
def eyes_annotations_loader(row, header=None):
"""
Convert leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
"""
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}")
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")]),
}
eyes = {
"leye": (row[find_attribute("leye_x")], row[find_attribute("leye_y")]),
"reye": (row[find_attribute("reye_x")], row[find_attribute("reye_y")]),
}
annotation = {"annotations": eyes}
annotation = {"annotations": eyes}
return annotation
return annotation
......@@ -345,6 +345,12 @@ def test_meds():
database = MEDSDatabase("verification_fold1")
assert len(database.background_model_samples()) == 234
assert len(database.references()) == 223 // 2
assert len(database.references()) == 111
assert len(database.probes()) == 313
assert len(database.references(group="dev"))
assert len(database.zprobes()) == 80
assert len(database.treferences()) == 80
assert len(database.references(group="eval")) == 112
assert len(database.probes(group="eval")) == 309
......@@ -20,6 +20,7 @@ Databases
bob.bio.face.database.LFWBioDatabase
bob.bio.face.database.MultipieBioDatabase
bob.bio.face.database.FargoBioDatabase
bob.bio.face.database.meds.MEDSDatabase
Face Image Annotators
......
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