Commit 87f0ff11 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Removed highlevel interfaces that we'll deprecate

parent f5a99f3e
Pipeline #39184 failed with stage
in 4 minutes and 19 seconds
#!/usr/bin/env python
from bob.bio.face.database import IJBABioDatabase
ijba_directory = "[YOUR_IJBA_DIRECTORY]"
database = IJBABioDatabase(
original_directory=ijba_directory,
protocol='search_split1'
)
#!/usr/bin/env python
from bob.bio.face.database import IJBBBioDatabase
ijbb_directory = "[YOUR_IJBB_DIRECTORY]"
database = IJBBBioDatabase(
original_directory=ijbb_directory,
protocol='1:1'
)
......@@ -5,14 +5,11 @@ from .database import FaceBioFile
from .mobio import MobioBioDatabase
from .replay import ReplayBioDatabase
from .atnt import AtntBioDatabase
from .banca import BancaBioDatabase
from .gbu import GBUBioDatabase
from .arface import ARFaceBioDatabase
from .caspeal import CaspealBioDatabase
from .lfw import LFWBioDatabase
from .multipie import MultipieBioDatabase
from .ijba import IJBABioDatabase
from .ijbb import IJBBBioDatabase
from .ijbc import IJBCBioDatabase
from .xm2vts import XM2VTSBioDatabase
from .frgc import FRGCBioDatabase
......@@ -43,15 +40,12 @@ __appropriate__(
FaceBioFile,
MobioBioDatabase,
ReplayBioDatabase,
AtntBioDatabase,
BancaBioDatabase,
AtntBioDatabase,
GBUBioDatabase,
ARFaceBioDatabase,
CaspealBioDatabase,
LFWBioDatabase,
MultipieBioDatabase,
IJBABioDatabase,
IJBBBioDatabase,
IJBCBioDatabase,
XM2VTSBioDatabase,
FRGCBioDatabase,
......
#!/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
"""
BANCA database implementation of bob.bio.base.database.ZTDatabase interface.
It is an extension of an SQL-based database interface, which directly talks to Banca database, for
verification experiments (good to use in bob.bio.base framework).
"""
from .database import FaceBioFile
from bob.bio.base.database import ZTBioDatabase
class BancaBioFile(FaceBioFile):
def __init__(self, f):
super(BancaBioFile, self).__init__(client_id=f.client_id, path=f.path, file_id=f.id)
self._f = f
class BancaBioDatabase(ZTBioDatabase):
"""
BANCA database implementation of :py:class:`bob.bio.base.database.ZTBioDatabase` interface.
It is an extension of an SQL-based database interface, which directly talks to Banca database, for
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
original_extension=None,
**kwargs
):
from bob.db.banca.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(original_directory, original_extension)
# call base class constructors to open a session to the database
super(BancaBioDatabase, self).__init__(
name='banca',
original_directory=original_directory,
original_extension=original_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 tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs):
return self._db.tmodel_ids(protocol=protocol, groups=groups, **kwargs)
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 [BancaBioFile(f) for f in retval]
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 [BancaBioFile(f) for f in retval]
def zobjects(self, groups=None, protocol=None, **kwargs):
retval = self._db.zobjects(groups=groups, protocol=protocol, **kwargs)
return [BancaBioFile(f) for f in retval]
def annotations(self, myfile):
return self._db.annotations(myfile._f)
#!/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
"""
IJBA database implementation of bob.bio.base.database.BioDatabase interface.
It is an extension of the database interface, which directly talks to IJBA database, for
verification experiments (good to use in bob.bio.base framework).
"""
from .database import FaceBioFile
from bob.bio.base.database import BioDatabase, BioFileSet
import os
import bob.io.image
class IJBABioFile(FaceBioFile):
def __init__(self, f):
super(IJBABioFile, self).__init__(
client_id=f.client_id, path=f.path, file_id=f.id)
self.f = f
def load(self, directory, extension=None, add_client_id=False):
return bob.io.image.load(self.make_path(directory, self.f.extension, add_client_id))
def make_path(self, directory, extension, add_client_id=True):
if add_client_id:
# add client ID to the path, so that a unique path is generated
# (there might be several identities in each physical file)
path = "%s-%s%s" % (self.path, self.client_id, extension or '')
else:
# do not add the client ID to be able to obtain the original image file
path = "%s%s" % (self.path, extension or '')
return str(os.path.join(directory or '', path))
class IJBABioFileSet(BioFileSet):
def __init__(self, template):
super(IJBABioFileSet, self).__init__(file_set_id=template.id, files=[
IJBABioFile(f) for f in template.files], path=template.path)
class IJBABioDatabase(BioDatabase):
"""
IJBA database implementation of :py:class:`bob.bio.base.database.BioDatabase` interface.
It is an extension of an SQL-based database interface, which directly talks to IJBA database, for
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
annotation_directory=None,
original_extension=None,
**kwargs
):
from bob.db.ijba.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(
original_directory, annotation_directory, original_extension)
# call base class constructors to open a session to the database
super(IJBABioDatabase, self).__init__(
name='ijba',
models_depend_on_protocol=True,
training_depends_on_protocol=True,
original_directory=original_directory,
annotation_directory=annotation_directory,
original_extension=original_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
@property
def annotation_directory(self):
return self._db.annotation_directory
@annotation_directory.setter
def annotation_directory(self, value):
self._db.annotation_directory = value
def uses_probe_file_sets(self):
return True
def model_ids_with_protocol(self, groups=None, protocol="search_split1", **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
def objects(self, groups=None, protocol="search_split1", purposes=None, model_ids=None, **kwargs):
return [IJBABioFile(f) for f in self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)]
def object_sets(self, groups=None, protocol="search_split1", purposes=None, model_ids=None):
return [IJBABioFileSet(t) for t in self._db.object_sets(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids)]
def annotations(self, biofile):
return self._db.annotations(biofile.f)
def client_id_from_model_id(self, model_id, group='dev'):
return self._db.get_client_id_from_model_id(model_id)
def original_file_names(self, files):
return [f.make_path(self.original_directory, f.f.extension, False) for f in files]
#!/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
"""
IJBB database implementation of bob.bio.base.database.BioDatabase interface.
It is an extension of the database interface, which directly talks to IJBB database, for
verification experiments (good to use in bob.bio.base framework).
"""
from .database import FaceBioFile
from bob.bio.base.database import BioDatabase, BioFileSet
import os
import bob.io.image
class IJBBBioFile(FaceBioFile):
def __init__(self, f):
super(IJBBBioFile, self).__init__(
client_id=f.client_id, path=f.path, file_id=f.id)
self.f = f
def load(self, directory, extension=None, add_client_id=False):
return bob.io.image.load(self.make_path(directory, self.f.extension, add_client_id))
def make_path(self, directory, extension, add_client_id=True):
if add_client_id:
# add client ID to the path, so that a unique path is generated
# (there might be several identities in each physical file)
path = "%s-%s%s" % (self.path, self.client_id, extension or '')
else:
# do not add the client ID to be able to obtain the original image file
path = "%s%s" % (self.path, extension or '')
return str(os.path.join(directory or '', path))
class IJBBBioFileSet(BioFileSet):
def __init__(self, template):
super(IJBBBioFileSet, self).__init__(file_set_id=template.id, files=[
IJBBBioFile(f) for f in template.files], path=template.path)
class IJBBBioDatabase(BioDatabase):
"""
IJBB database implementation of :py:class:`bob.bio.base.database.BioDatabase` interface.
It is an extension of an SQL-based database interface, which directly talks to IJBB database, for
verification experiments (good to use in bob.bio.base framework).
"""
def __init__(
self,
original_directory=None,
annotation_directory=None,
original_extension=None,
**kwargs
):
from bob.db.ijbb.query import Database as LowLevelDatabase
self._db = LowLevelDatabase(
original_directory)
# call base class constructors to open a session to the database
super(IJBBBioDatabase, self).__init__(
name='ijbb',
models_depend_on_protocol=True,
training_depends_on_protocol=True,
original_directory=original_directory,
annotation_directory=annotation_directory,
original_extension=original_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
@property
def annotation_directory(self):
return self._db.annotation_directory
@annotation_directory.setter
def annotation_directory(self, value):
self._db.annotation_directory = value
def uses_probe_file_sets(self):
return True
def model_ids_with_protocol(self, groups=None, protocol="1:1", **kwargs):
return self._db.model_ids(groups=groups, protocol=protocol)
def objects(self, groups=None, protocol="1:1", purposes=None, model_ids=None, **kwargs):
return [IJBBBioFile(f) for f in self._db.objects(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids, **kwargs)]
def object_sets(self, groups=None, protocol="1:1", purposes=None, model_ids=None):
return [IJBBBioFileSet(t) for t in self._db.object_sets(groups=groups, protocol=protocol, purposes=purposes, model_ids=model_ids)]
def annotations(self, biofile):
return self._db.annotations(biofile.f)
def client_id_from_model_id(self, model_id, group='dev'):
return self._db.get_client_id_from_model_id(self.protocol, model_id)
def original_file_names(self, files):
return [f.make_path(self.original_directory, f.f.extension, False) for f in files]
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
"""
This script parses through the given directory, collects all results of
experiments using bob.db.ijba and dumps a nice copy/paste ReStructuredText (RST).
It supports comparison (--report-type comparison) and search (--report-type search) experiments
For comparison, the following command dumps:
./bin/bob_ijba_collect_results.py <comparison-path> -r comparison
+-----------------+-----------------+-----------------+-----------------+--------------------------+
| RR | TPIR% (FAR=0.1) | TPIR% (FAR=0.01)|TPIR% (FAR=0.001)| split |
+=================+=================+=================+=================+==========================+
| 00000 |0000000 |00000000 |00000 |split 0 |
+-----------------+-----------------+-----------------+-----------------+--------------------------+
| |
For search, the following command dumps:
./bin/bob_ijba_collect_results.py <search-path> -r search
+-------------------------+-------------------------+--------------------------+
| DIR% (rank=1, FAR=0.1) | DIR% (rank=1, FAR=0.01) | split |
+=========================+=========================+==========================+
| 00000 |000000 |00000000 |
"""
from __future__ import print_function
import sys, os, glob
import argparse
import numpy
import bob.measure
import bob.core
from argparse import RawTextHelpFormatter
from bob.bio.base.script.collect_results import Result, recurse, add_results
far_thresholds = [0.1, 0.01, 0.001]
logger = bob.core.log.setup("bob.bio.base")
def command_line_arguments(command_line_parameters):
"""Parse the program options"""
# set up command line parser
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=RawTextHelpFormatter)
parser.add_argument('directory', default=".", help = "The directory where the results should be collected from.")
parser.add_argument('-r', '--report-type', default="comparison", choices=("comparison", "search"), help = "Type of the report. For `comparison`, RR and TPIR (FAR=[0.1, 0.01 and 0.001] ) will be reported. For the search DIR (rank=1, under FAR=[0.1, 0.01]) is reported")
bob.core.log.add_command_line_option(parser)
# parse arguments
args = parser.parse_args(command_line_parameters)
bob.core.log.set_verbosity_level(logger, args.verbose)
return args
def search_results(args, directories):
"""
Navigates throught the directories collection evaluation results
"""
results = []
for directory in directories:
r = recurse(args, directory)
if r is not None:
results += r
return results
def compute_mean_std(results):
return numpy.mean([r.nonorm_dev for r in results]), numpy.std([r.nonorm_dev for r in results])
def compute_comparison(args, directories):
"""
Plot evaluation table for the comparison protocol
"""
def plot_comparison_table(cmc_r1, fnmr):
grid = "+-----------------+-----------------+-----------------+-----------------+--------------------------+\n"
grid += "| RR | TPIR% (FAR=0.1) | TPIR% (FAR=0.01)|TPIR% (FAR=0.001)| split |\n"
grid += "+=================+=================+=================+=================+==========================+\n"
for cmc, fnmr_0, fnmr_1, fnmr_2, split in zip(cmc_r1, fnmr[0], fnmr[1], fnmr[2], range(len(cmc_r1))):
grid += "|{:17s}|{:17s}|{:17s}|{:17s}|{:26s}|\n".format(str(round(cmc.nonorm_dev,5)*100),
str(round(fnmr_0.nonorm_dev,5)*100),
str(round(fnmr_1.nonorm_dev,5)*100),
str(round(fnmr_2.nonorm_dev,5)*100),
"split {0}".format(split))
grid += "+-----------------+-----------------+-----------------+-----------------+--------------------------+\n"
cmc = compute_mean_std(cmc_r1)
fnmr_0 = compute_mean_std(fnmr[0])
fnmr_1 = compute_mean_std(fnmr[1])
fnmr_2 = compute_mean_std(fnmr[2])
grid += "|**{:6s}({:5s})**|**{:6s}({:5s})**|**{:6s}({:5s})**|**{:6s}({:5s})**|{:26s}|\n".format(
str(round(cmc[0],4)*100),str(round(cmc[1],4)*100),
str(round(fnmr_0[0],4)*100),str(round(fnmr_0[1],4)*100),
str(round(fnmr_1[0],4)*100),str(round(fnmr_1[1],4)*100),
str(round(fnmr_2[0],4)*100),str(round(fnmr_2[1],4)*100),
"mean(std)")
grid += "+-----------------+-----------------+-----------------+-----------------+--------------------------+\n"
return grid
def compute_fnmr(args, directories):
fnmr = []
for f in far_thresholds:
args.criterion = "FAR"
args.far_threshold = f
# Computing TPIR
frr = search_results(args, directories)
for rr in frr:
rr.nonorm_dev = 1.-rr.nonorm_dev
fnmr.append(frr)
return fnmr
args = args
args.rank = 1
args.criterion = "RR"
cmc_r1 = search_results(args, directories)
fnmr = compute_fnmr(args, directories)
return plot_comparison_table(cmc_r1, fnmr)
def compute_search(args, directories):
"""
Plot evaluation table for the search protocol
"""
def plot_search_table(dira):
grid = "+----------------------+----------------------+--------------------------+\n"
grid += "| DIR% (R=1, FAR=0.1) | DIR% (R=1, FAR=0.01) | split |\n"
grid += "+======================+======================+==========================+\n"
n_splits = len(dira[0])
for dira_0, dira_1, split in zip(dira[0], dira[1], range(n_splits)):
grid += "|{:22s}|{:22s}|{:26s}|\n".format(str(round(dira_0.nonorm_dev,5)*100),
str(round(dira_1.nonorm_dev,5)*100),
"split {0}".format(split))
grid += "+----------------------+----------------------+--------------------------+\n"
dira_0 = compute_mean_std(dira[0])
dira_1 = compute_mean_std(dira[1])
grid += "|**{:6s}({:6s})** |**{:6s}({:6s})** |{:26s}|\n".format(
str(round(dira_0[0],4)*100),str(round(dira_0[1],4)*100),
str(round(dira_1[0],4)*100),str(round(dira_1[1],4)*100),
"mean(std)")
grid += "+----------------------+----------------------+--------------------------+\n"
return grid
def compute_dir(args, directories):
dira = []
for f in far_thresholds[0:2]:
args.criterion = "DIR"
args.far_threshold = f
dira.append(search_results(args, directories))
return dira
args = args
args.rank = 1
args.criterion = "DIR"
dira = compute_dir(args, directories)
return plot_search_table(dira)
def main(command_line_parameters = None):
"""Iterates through the desired directory and collects all result files."""
args = command_line_arguments(command_line_parameters)
# collect results
if not os.path.exists(args.directory):
raise ValueError("The directory `%s` does not exists"%args.directory)
# Injecting some variables
args.dev = "scores-dev"
args.eval = "scores-eval"
args.nonorm = "nonorm"
args.ztnorm = "ztnorm"
if args.report_type == "comparison":
print(compute_comparison(args, [args.directory]))
else:
print(compute_search(args, [args.directory]))
......@@ -81,22 +81,6 @@ def test_atnt():
"The database could not queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
@db_available('banca')
def test_banca():
database = bob.bio.base.load_resource(
'banca', 'database', preferred_package='bob.bio.face')
try:
check_database_zt(database)
except IOError as e:
raise SkipTest(
"The database could not be queried; probably the db.sql3 file is missing. Here is the error: '%s'" % e)
try:
_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)
@db_available('caspeal')
def test_caspeal():
database = bob.bio.base.load_resource(
......@@ -145,22 +129,6 @@ def test_gbu():
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
@db_available('ijba')
def test_ijba():
database = bob.bio.base.load_resource(
'ijba', 'database', preferred_package='bob.bio.face')
try:
check_database(database, models_depend=True, training_depends=True)
except IOError as e:
raise SkipTest(
"The database could not queried. Here is the error: '%s'" % e)
try:
_check_annotations(database, topleft=True, limit_files=1000)
except IOError as e:
raise SkipTest(
"The annotations could not be queried; probably the annotation files are missing. Here is the error: '%s'" % e)
@db_available('lfw')
def test_lfw():
database = bob.bio.base.load_resource(
......@@ -357,22 +325,6 @@ def test_msu_mfsd_mod_spoof():
raise SkipTest(
"The annotations could not be queried; probably the annotation " <