Ported MultiPIE as CSVDatabase

parent fd3edbd3
Pipeline #46724 passed with stage
in 45 minutes and 5 seconds
#!/usr/bin/env python
from bob.bio.face.database import MultipieBioDatabase
from bob.bio.base.pipelines.vanilla_biometrics import DatabaseConnector
from bob.extension import rc
from bob.bio.face.database import MultipieDatabase
multipie_image_directory = rc["bob.db.multipie.directory"]
multipie_annotation_directory = rc["bob.db.multipie.annotations"]
database = DatabaseConnector(
MultipieBioDatabase(
original_directory=multipie_image_directory,
annotation_directory=multipie_annotation_directory,
protocol="U",
training_depends_on_protocol=True,
)
)
database = MultipieDatabase(protocol="U")
#!/usr/bin/env python
from bob.bio.face.database import MultipieDatabase
from bob.bio.face.database import MultipieBioDatabase
from bob.bio.base.pipelines.vanilla_biometrics import DatabaseConnector
from bob.extension import rc
# here, we only want to have the cameras that are used in the P protocol
cameras = (
"24_0",
"01_0",
"20_0",
"19_0",
"04_1",
"05_0",
"05_1",
"14_0",
"13_0",
"08_0",
"09_0",
"12_0",
"11_0",
)
multipie_image_directory = rc["bob.db.multipie.directory"]
multipie_annotation_directory = rc["bob.db.multipie.annotations"]
database = DatabaseConnector(
MultipieBioDatabase(
original_directory=multipie_image_directory,
annotation_directory=multipie_annotation_directory,
protocol="P",
training_depends_on_protocol=True,
all_files_options={"cameras": cameras},
extractor_training_options={"cameras": cameras},
projector_training_options={
"cameras": cameras,
"world_sampling": 3,
"world_first": True,
},
enroller_training_options={"cameras": cameras},
)
)
database = MultipieDatabase(protocol="P")
......@@ -8,7 +8,7 @@ from .atnt import AtntBioDatabase
from .gbu import GBUBioDatabase
from .arface import ARFaceBioDatabase
from .lfw import LFWBioDatabase
from .multipie import MultipieBioDatabase
from .multipie import MultipieDatabase
from .ijbc import IJBCBioDatabase
from .replaymobile import ReplayMobileBioDatabase
from .fargo import FargoBioDatabase
......@@ -41,7 +41,7 @@ __appropriate__(
GBUBioDatabase,
ARFaceBioDatabase,
LFWBioDatabase,
MultipieBioDatabase,
MultipieDatabase,
IJBCBioDatabase,
ReplayMobileBioDatabase,
FargoBioDatabase,
......
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# Sat 20 Aug 15:43:10 CEST 2016
"""
Multipie database implementation of bob.bio.base.database.Database interface.
It is an extension of an SQL-based database interface, which directly talks to Multipie database, for
verification experiments (good to use in bob.bio.base framework).
Multipie database implementation
"""
from .database import FaceBioFile
from bob.bio.base.database import ZTBioDatabase
from bob.bio.base.database import CSVDataset
from bob.pipelines.datasets import CSVToSampleLoader
from bob.bio.face.database.sample_loaders import MultiposeAnnotations
from bob.extension import rc
from bob.extension.download import get_file
import bob.io.base
from sklearn.pipeline import make_pipeline
class MultipieBioFile(FaceBioFile):
def __init__(self, f):
super(MultipieBioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id)
self._f = f
class MultipieBioDatabase(ZTBioDatabase):
class MultipieDatabase(CSVDataset):
"""
Multipie database implementation of bob.bio.base.database.Database interface.
It is an extension of an SQL-based database interface, which directly talks to Multipie database, for
verification experiments (good to use in bob.bio.base framework).
The Multipie database..
"""
def __init__(
self,
original_directory=None,
original_extension='.png',
annotation_directory=None,
annotation_extension='.pos',
**kwargs
):
from bob.db.multipie.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory,
original_extension,
annotation_directory,
annotation_extension)
# call base class constructors to open a session to the database
super(MultipieBioDatabase, self).__init__(
name='multipie',
original_directory=original_directory,
original_extension=original_extension,
annotation_directory=annotation_directory,
annotation_extension=annotation_extension,
**kwargs)
@property
def original_directory(self):
return self._db.original_directory
@original_directory.setter
def original_directory(self, value):
self._db.original_directory = value
def model_ids_with_protocol(self, groups=None, protocol=None, **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
retval = self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)
return [MultipieBioFile(f) for f in retval]
def tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
return self._db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
def tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs):
retval = self._db.tobjects(groups=groups, protocol=protocol, model_ids=model_ids, **kwargs)
return [MultipieBioFile(f) for f in retval]
def zobjects(self, groups=None, protocol=None, **kwargs):
retval = self._db.zobjects(groups=groups, protocol=protocol, **kwargs)
return [MultipieBioFile(f) for f in retval]
def annotations(self, myfile):
return self._db.annotations(myfile._f)
def __init__(self, protocol):
# Downloading model if not exists
urls = [
"https://www.idiap.ch/software/bob/databases/latest/multipie.tar.gz",
"http://www.idiap.ch/software/bob/databases/latest/multipie.tar.gz",
]
filename = get_file("multipie.tar.gz", urls)
self.annotation_type = ["eyes-center", "left-profile", "right-profile"]
self.fixed_positions = None
super().__init__(
filename,
protocol,
csv_to_sample_loader=make_pipeline(
CSVToSampleLoader(
data_loader=bob.io.base.load,
dataset_original_directory=rc["bob.db.multipie.directory"]
if rc["bob.db.multipie.directory"]
else "",
extension=".png",
),
MultiposeAnnotations(),
),
)
@staticmethod
def protocols():
# TODO: Until we have (if we have) a function that dumps the protocols, let's use this one.
return [
"P240",
"P191",
"P130",
"G",
"P010",
"P041",
"P051",
"P050",
"M",
"P110",
"P",
"P140",
"U",
"P200",
"E",
"P190",
"P120",
"P080",
"P081",
"P090",
]
......@@ -8,6 +8,13 @@ from bob.pipelines import DelayedSample, Sample, SampleSet
from sklearn.base import TransformerMixin, BaseEstimator
def find_attribute(x, attribute):
if hasattr(x, attribute):
return getattr(x, attribute)
else:
ValueError(f"Attribute not found in the dataset: {attribute}")
class EyesAnnotations(TransformerMixin, BaseEstimator):
def fit(self, X, y=None):
return self
......@@ -23,12 +30,6 @@ class EyesAnnotations(TransformerMixin, BaseEstimator):
Convert leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
"""
def find_attribute(x, attribute):
if hasattr(x, attribute):
return getattr(x, attribute)
else:
ValueError(f"Attribute not found in the dataset: {attribute}")
annotated_samples = []
for x in X:
eyes = {
......@@ -47,3 +48,85 @@ class EyesAnnotations(TransformerMixin, BaseEstimator):
annotated_samples.append(sample)
return annotated_samples
class MultiposeAnnotations(TransformerMixin, BaseEstimator):
def fit(self, X, y=None):
return self
def _more_tags(self):
return {
"stateless": True,
"requires_fit": False,
}
def transform(self, X):
annotated_samples = []
for x in X:
annotations = dict()
if find_attribute(x, "leye_x") != "" and find_attribute(x, "reye_x") != "":
# Normal profile
annotations = {
"leye": (
float(find_attribute(x, "leye_x")),
float(find_attribute(x, "leye_y")),
),
"reye": (
float(find_attribute(x, "reye_x")),
float(find_attribute(x, "reye_y")),
),
}
elif (
find_attribute(x, "leye_x") != "" and find_attribute(x, "reye_x") == ""
):
# Left profile
annotations = {
"leye": (
float(find_attribute(x, "leye_x")),
float(find_attribute(x, "leye_y")),
),
"mouth": (
float(find_attribute(x, "mouthl_x")),
float(find_attribute(x, "mouthl_y")),
),
}
elif (
find_attribute(x, "leye_x") == "" and find_attribute(x, "reye_x") != ""
):
# Right profile
annotations = {
"leye": (
float(find_attribute(x, "reye_x")),
float(find_attribute(x, "reye_y")),
),
"mouth": (
float(find_attribute(x, "mouthr_x")),
float(find_attribute(x, "mouthr_y")),
),
}
else:
raise ValueError("Annotations not available")
sample = DelayedSample(x._load, parent=x, annotations=annotations)
[
delattr(sample, a)
for a in [
"reye_x",
"reye_y",
"leye_x",
"leye_y",
"nose_x",
"nose_y",
"mouthr_x",
"mouthr_y",
"mouthl_x",
"mouthl_y",
"chin_x",
"chin_y",
]
]
annotated_samples.append(sample)
return annotated_samples
......@@ -186,39 +186,29 @@ def test_mobio():
assert len(database.probes(group="eval")) == 3990
@db_available("multipie")
def test_multipie():
database = bob.bio.base.load_resource(
"multipie", "database", preferred_package="bob.bio.face"
)
try:
check_database_zt(database, training_depends=True)
check_database_zt(
bob.bio.base.load_resource(
"multipie-pose", "database", preferred_package="bob.bio.face"
),
training_depends=True,
)
except IOError as e:
raise SkipTest(
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'"
% e
)
except ValueError as e:
raise SkipTest(
"The database could not queried; probably the protocol is missing inside the db.sql3 file. Here is the error: '%s'"
% e
)
from bob.bio.face.database import MultipieDatabase
try:
if database.database.annotation_directory is None:
raise SkipTest("The annotation directory is not set")
_check_annotations(database)
except IOError as e:
raise SkipTest(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'"
% e
)
protocols = MultipieDatabase.protocols()
for p in protocols:
database = MultipieDatabase(protocol=p)
assert len(database.background_model_samples()) > 0
assert len(database.references(group="dev")) > 0
assert len(database.probes(group="dev")) > 0
assert len(database.references(group="eval")) > 0
assert len(database.probes(group="eval")) > 0
database = MultipieDatabase(protocol="P")
assert len(database.background_model_samples()) == 7725
assert len(database.references(group="dev")) == 64
assert len(database.probes(group="dev")) == 3328
assert len(database.references(group="eval")) == 65
assert len(database.probes(group="eval")) == 3380
@db_available("replay")
......
......@@ -75,7 +75,6 @@ test:
- bob.db.gbu
- bob.db.ijbc
- bob.db.lfw
- bob.db.multipie
- bob.db.replay
- bob.db.replaymobile
- bob.db.xm2vts
......
......@@ -18,7 +18,7 @@ Databases
bob.bio.face.database.ReplayMobileBioDatabase
bob.bio.face.database.GBUBioDatabase
bob.bio.face.database.LFWBioDatabase
bob.bio.face.database.MultipieBioDatabase
bob.bio.face.database.MultipieDatabase
bob.bio.face.database.FargoBioDatabase
bob.bio.face.database.MEDSDatabase
bob.bio.face.database.MorphDatabase
......
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