Commit 82b3e313 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira

Merge branch 'annotations' into 'master'

Sample Loaders able to handle certain type of annotations...

See merge request !81
parents 0b34b777 5612c3af
Pipeline #46349 passed with stages
in 42 minutes and 45 seconds
include README.rst bootstrap-buildout.py buildout.cfg develop.cfg LICENSE version.txt requirements.txt
recursive-include doc *.py *.rst
recursive-include bob/bio/face/test/data *.hdf5 *.jpg *.pos *.png *.json
recursive-include bob/bio/face/test/data *.hdf5 *.jpg *.pos *.png *.json *.tar.gz
......@@ -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,22 @@ 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,
MEDSDatabase,
)
__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,
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 eyes_annotations_loader
import os
cache_subdir = "datasets"
filename = "meds.tar.gz"
dataset_protocol_path = os.path.join(
os.path.expanduser("~"), "bob_data", cache_subdir, filename
)
class MEDSDatabase(CSVDatasetDevEvalZTNorm):
"""
The MEDS-II (Multiple Encounter Data Set II) database interface
.. warning::
Use the command below to set the path of the real data::
$ 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"]
if rc["bob.db.meds.directory"]
else "",
extension=".jpg",
),
)
super().__init__(database)
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
""" Sample and Metatada loaders"""
def eyes_annotations_loader(row, header=None):
"""
Convert leye_x, leye_y, reye_x, reye_y attributes to `annotations = (leye, reye)`
"""
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")]),
}
annotation = {"annotations": eyes}
return annotation
......@@ -96,8 +96,7 @@ def test_gabor_jet():
def test_histogram():
histogram = bob.bio.face.algorithm.Histogram(
distance_function = bob.math.histogram_intersection,
is_distance_function = False
distance_function=bob.math.histogram_intersection, is_distance_function=False
)
assert isinstance(histogram, bob.bio.face.algorithm.Histogram)
......@@ -150,29 +149,3 @@ def test_histogram():
)
< 1e-5
)
def test_bic_jets():
similarity_function = bob.ip.gabor.Similarity("PhaseDiffPlusCanberra", bob.ip.gabor.Transform())
def gabor_jet_similarities(f1, f2):
"""Computes the similarity vector between two Gabor graph features"""
assert len(f1) == len(f2)
return [similarity_function(f1[i], f2[i]) for i in range(len(f1))]
bic = bob.bio.base.algorithm.BIC(
# measure to compare two features in input space
comparison_function = gabor_jet_similarities,
# load and save functions
read_function = bob.ip.gabor.load_jets,
write_function = bob.ip.gabor.save_jets,
# Limit the number of training pairs
maximum_training_pair_count = 1000000,
# Dimensions of intrapersonal and extrapersonal subspaces
subspace_dimensions = (20, 20),
multiple_model_scoring = 'max'
)
assert isinstance(bic, bob.bio.base.algorithm.BIC)
assert isinstance(bic, bob.bio.base.algorithm.Algorithm)
......@@ -42,7 +42,7 @@ def get_fake_sample_set(face_size=(160, 160), purpose="bioref"):
)
],
key=key,
subject=key,
reference_id=key,
references=["1"],
)
]
......@@ -54,7 +54,7 @@ def get_fake_samples_for_training():
annotations = {"reye": (131, 176), "leye": (222, 170)}
return [
Sample(x, key=str(i), subject=str(i), annotations=annotations)
Sample(x, key=str(i), reference_id=str(i), annotations=annotations)
for i, x in enumerate(data)
]
......
This diff is collapsed.
......@@ -40,7 +40,7 @@ def test_idiap_inceptionv2_msceleb_memory_demanding():
reference = bob.io.base.load(
pkg_resources.resource_filename(
"bob.bio.face.test", "data/inception_resnet_v2_rgb.hdf5"
"bob.bio.face.test", "data/inception_resnet_v2_msceleb_rgb.hdf5"
)
)
np.random.seed(10)
......
......@@ -4,36 +4,45 @@ import tempfile
import shutil
import os
def test_display_annotations():
from bob.bio.face.script.display_face_annotations import display_face_annotations
try:
tmp_dir = tempfile.mkdtemp(prefix="bobtest_")
annotations_dir = pkg_resources.resource_filename(
"bob.bio.face.test",
"data/annotations/"
"bob.bio.face.test", "data/annotations/"
)
runner = CliRunner()
result = runner.invoke(
display_face_annotations,
args=(
'--database', 'dummy',
'--groups', 'world', '--groups', 'dev',
'--annotations-dir', annotations_dir,
'--output-dir', tmp_dir, '--keep-all',
'--self-test',
)
"--database",
"dummy",
"--groups",
"train",
"--groups",
"dev",
"--annotations-dir",
annotations_dir,
"--output-dir",
tmp_dir,
"--keep-all",
"--self-test",
),
)
assertion_error_message = (
'Command exited with this output: `{}\' \n'
'If the output is empty, you can run this script locally to see '
'what is wrong:\n'
'$ bob bio display_face_annotations -vvv -d dummy -g world -g dev -a ./annotations/ -o /tmp/temp_annotated'
''.format(result.output))
"Command exited with this output: `{}' \n"
"If the output is empty, you can run this script locally to see "
"what is wrong:\n"
"$ bob bio display-face-annotations -vvv -d dummy -g train -g dev -a ./annotations/ -o /tmp/temp_annotated"
"".format(result.output)
)
assert result.exit_code == 0, assertion_error_message
# Checks if an annotated sample exists
sample_1_path = os.path.join(tmp_dir, "s1","1.png")
sample_1_path = os.path.join(tmp_dir, "s1", "1.png")
assertion_error_message = "File '{}' not created.".format(sample_1_path)
assert os.path.isfile(sample_1_path), assertion_error_message
......
......@@ -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