Skip to content
Snippets Groups Projects
Commit 483dfd72 authored by Pavel KORSHUNOV's avatar Pavel KORSHUNOV
Browse files

Fixing Issue #54

parents fab9e1f6 91826f62
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -8,7 +8,7 @@ import bob.learn.linear
import numpy
import math
from .Algorithm import Algorithm
from bob.bio.base.algorithm import Algorithm
from .. import utils
import logging
......@@ -255,7 +255,8 @@ class BIC(Algorithm):
Computes the BIC score between the model and the probe.
First, the ``comparison_function`` is used to create the comparison vectors between all model features and the probe feature.
Then, a BIC score is computed for each comparison vector, and the BIC scores are fused using the :py:func:`model_fusion_function` defined in the :py:class:`Algorithm` base class.
Then, a BIC score is computed for each comparison vector, and the BIC scores are fused using
the `model_fusion_function` defined in the :py:class:`bob.bio.base.algorithm.Algorithm` base class.
**Parameters:**
......
......@@ -5,5 +5,35 @@ from .LDA import LDA
from .PLDA import PLDA
from .BIC import BIC
# # to fix sphinx warnings of not being able to find classes, when path is shortened
# Algorithm.__module__ = "bob.bio.base.algorithm"
# Distance.__module__ = "bob.bio.base.algorithm"
# PCA.__module__ = "bob.bio.base.algorithm"
# LDA.__module__ = "bob.bio.base.algorithm"
# PLDA.__module__ = "bob.bio.base.algorithm"
# BIC.__module__ = "bob.bio.base.algorithm"
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
"""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:
*args: An iterable of objects to modify
Resolves `Sphinx referencing issues
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for obj in args: obj.__module__ = __name__
__appropriate__(
Algorithm,
Distance,
PCA,
LDA,
PLDA,
BIC,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
......@@ -3,5 +3,30 @@ from .file import BioFileSet
from .database import BioDatabase
from .database import ZTBioDatabase
# to fix sphinx warnings of not being able to find classes, when path is shortened
BioFile.__module__ = "bob.bio.base.database"
BioFileSet.__module__ = "bob.bio.base.database"
BioDatabase.__module__ = "bob.bio.base.database"
ZTBioDatabase.__module__ = "bob.bio.base.database"
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
"""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:
*args: An iterable of objects to modify
Resolves `Sphinx referencing issues
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for obj in args: obj.__module__ = __name__
__appropriate__(
BioFile,
BioFileSet,
BioDatabase,
ZTBioDatabase,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
......@@ -49,7 +49,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
The file name extension of the annotation files.
annotation_type : str
The type of the annotation file to read, see `bob.db.base.annotations.read_annotation_file` for accepted formats.
The type of the annotation file to read, see `bob.db.base.read_annotation_file` for accepted formats.
protocol : str or ``None``
The name of the protocol that defines the default experimental setup for this database.
......@@ -65,7 +65,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
This flag is used to avoid re-computation of models when running on the different protocols of the same database.
kwargs : ``key=value`` pairs
The arguments of the :py:class:`Database` base class constructor.
The arguments of the `Database` base class constructor.
"""
def __init__(
......@@ -215,12 +215,12 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Parameters:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The list of files to be uniquified and sorted.
**Returns:**
sorted : [:py:class:`BioFile`]
sorted : [:py:class:`bob.bio.base.database.BioFile`]
The sorted list of files, with duplicate `BioFile.id`\s being removed.
"""
# sort files using their sort function
......@@ -243,12 +243,12 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Parameters:**
files : :py:class:`BioFile`
files : :py:class:`bob.bio.base.database.BioFile`
A list of files that should be split up by `BioFile.client_id`.
**Returns:**
files_by_client : [[:py:class:`BioFile`]]
files_by_client : [[:py:class:`bob.bio.base.database.BioFile`]]
The list of lists of files, where each sub-list groups the files with the same `BioFile.client_id`
"""
client_files = {}
......@@ -265,11 +265,11 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
def annotations(self, file):
"""
Returns the annotations for the given File object, if available.
It uses `bob.db.base.annotations.read_annotation_file` to load the annotations.
It uses `bob.db.base.read_annotation_file` to load the annotations.
**Parameters:**
file : :py:class:`BioFile`
file : :py:class:`bob.bio.base.database.BioFile`
The file for which annotations should be returned.
**Returns:**
......@@ -294,7 +294,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Parameters:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The list of file object to retrieve the file names for.
directory : str
......@@ -324,7 +324,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Parameters:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The list of file object to retrieve the original data file names for.
**Returns:**
......@@ -414,7 +414,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
Keyword parameters:
file : :py:class:`BioFile` or a derivative
file : :py:class:`bob.bio.base.database.BioFile` or a derivative
The File objects for which the file name should be retrieved
Return value : str
......@@ -445,7 +445,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Returns:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The sorted and unique list of all files of the database.
"""
return self.sort(self.objects(protocol=self.protocol, groups=groups, **self.all_files_options))
......@@ -468,7 +468,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Returns:**
files : [:py:class:`BioFile`] or [[:py:class:`BioFile`]]
files : [:py:class:`bob.bio.base.database.BioFile`] or [[:py:class:`bob.bio.base.database.BioFile`]]
The (arranged) list of files used for the training of the given step.
"""
if step is None:
......@@ -503,7 +503,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Returns:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The sorted and unique list of test files of the database.
"""
return self.sort(self.objects(protocol=self.protocol, groups=groups, **self.all_files_options))
......@@ -552,7 +552,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Returns:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The list of files used for to probe the model with the given model id.
"""
if model_id is not None:
......@@ -606,7 +606,7 @@ class BioDatabase(six.with_metaclass(abc.ABCMeta, bob.db.base.Database)):
**Returns:**
files : [:py:class:`BioFileSet`] or something similar
files : [:py:class:`bob.bio.base.database.BioFileSet`] or something similar
The list of file sets used to probe the model with the given model id."""
if model_id is not None:
file_sets = self.object_sets(protocol=self.protocol, groups=group, model_ids=(model_id,), purposes='probe',
......@@ -715,7 +715,7 @@ class ZTBioDatabase(BioDatabase):
**Returns:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The sorted and unique list of all files of the database.
"""
files = self.objects(protocol=self.protocol, groups=groups, **self.all_files_options)
......@@ -777,7 +777,7 @@ class ZTBioDatabase(BioDatabase):
**Returns:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The sorted list of files used for to enroll the model with the given model id.
"""
return self.sort(self.tobjects(protocol=self.protocol, groups=group, model_ids=(t_model_id,)))
......@@ -795,7 +795,7 @@ class ZTBioDatabase(BioDatabase):
**Returns:**
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
The unique list of files used to compute the Z-norm.
"""
return self.sort(self.zobjects(protocol=self.protocol, groups=group, **self.z_probe_options))
......@@ -813,7 +813,7 @@ class ZTBioDatabase(BioDatabase):
**Returns:**
files : [:py:class:`BioFileSet`]
files : [:py:class:`bob.bio.base.database.BioFileSet`]
The unique list of file sets used to compute the Z-norm.
"""
raise NotImplementedError("Please implement this function in derived classes")
......
......@@ -18,7 +18,7 @@ class BioFile(bob.db.base.File):
The id of the client this file belongs to.
Its type depends on your implementation.
If you use an SQL database, this should be an SQL type like Integer or String.
For path and file_id, please refer to :py:class:`bob.db.base.file.File` constructor
For path and file_id, please refer to :py:class:`bob.db.base.File` constructor
"""
bob.db.base.File.__init__(self, path, file_id)
......@@ -30,19 +30,22 @@ class BioFile(bob.db.base.File):
class BioFileSet(BioFile):
"""This class defines the minimum interface of a set of database files that needs to be exported.
Use this class, whenever the database provides several files that belong to the same probe.
Each file set has an id, and a list of associated files, which are of type :py:class:`BioFile` of the same client.
Each file set has an id, and a list of associated files, which are of
type :py:class:`bob.bio.base.database.BioFile` of the same client.
The file set id can be anything hashable, but needs to be unique all over the database.
**Parameters:**
file_set_id : str or int
A unique ID that identifies the file set.
files : [:py:class:`BioFile`]
files : [:py:class:`bob.bio.base.database.BioFile`]
A non-empty list of BioFile objects that should be stored inside this file.
All files of that list need to have the same client ID.
"""
def __init__(self, file_set_id, files, path=None):
"""The list of :py:class:`bob.bio.base.database.BioFile` objects stored in this file set"""
# don't accept empty file lists
assert len(files), "Cannot create an empty BioFileSet"
......@@ -55,7 +58,6 @@ class BioFileSet(BioFile):
# The list of files contained in this set
self.files = files
"""The list of :py:class:`BioFile` objects stored in this file set"""
def __lt__(self, other):
"""Defines an order between file sets by using the order of the file set ids."""
......
from .Extractor import Extractor
from .Linearize import Linearize
# to fix sphinx warnings of not being able to find classes, when path is shortened
Extractor.__module__ = "bob.bio.base.extractor"
Linearize.__module__ = "bob.bio.base.extractor"
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
"""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:
*args: An iterable of objects to modify
Resolves `Sphinx referencing issues
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for obj in args: obj.__module__ = __name__
__appropriate__(
Extractor,
Linearize,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
from .Preprocessor import Preprocessor
from .Filename import Filename
# to fix sphinx warnings of not being able to find classes, when path is shortened
Preprocessor.__module__ = "bob.bio.base.preprocessor"
Filename.__module__ = "bob.bio.base.preprocessor"
# gets sphinx autodoc done right - don't remove it
def __appropriate__(*args):
"""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:
*args: An iterable of objects to modify
Resolves `Sphinx referencing issues
<https://github.com/sphinx-doc/sphinx/issues/3048>`
"""
for obj in args: obj.__module__ = __name__
__appropriate__(
Preprocessor,
Filename,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
......@@ -253,6 +253,33 @@ def test_verify_missing():
shutil.rmtree(test_dir)
def test_verify_execute_only():
test_dir = tempfile.mkdtemp(prefix='bobtest_')
# define dummy parameters
parameters = [
'-d', 'dummy',
'-p', 'dummy',
'-e', 'dummy',
'-a', 'dummy',
'--zt-norm',
'--allow-missing-files',
'-vs', 'test_missing',
'--temp-directory', test_dir,
'--result-directory', test_dir,
'--preferred-package', 'bob.bio.base',
'--imports', 'bob.bio.base.test.dummy',
'--execute-only', 'preprocessing', 'score-computation',
'--dry-run'
]
try:
from bob.bio.base.script.verify import main
main(parameters)
finally:
if os.path.exists(test_dir):
shutil.rmtree(test_dir)
def test_internal_raises():
test_dir = tempfile.mkdtemp(prefix='bobtest_')
# define dummy parameters
......
......@@ -166,6 +166,10 @@ def _take_from_config_or_command_line(args, config, keyword, default, required=T
val = utils.load_resource(val, keyword, imports = args.imports, preferred_package = args.preferred_package)
setattr(args, keyword, val)
elif default is not None:
if is_resource:
setattr(args, keyword, utils.load_resource(' '.join(default), keyword, imports = args.imports, preferred_package = args.preferred_package))
elif required:
raise ValueError("Please specify a %s either on command line (via --%s) or in a configuration file" %(keyword, keyword))
......@@ -222,10 +226,10 @@ def initialize(parsers, command_line_parameters = None, skips = []):
parser.get_default(keyword))
_take_from_config_or_command_line(args, config, "grid",
parser.get_default(keyword), required=False)
parser.get_default('grid'), required=False)
_take_from_config_or_command_line(args, config, "sub_directory",
parser.get_default(keyword), is_resource=False)
parser.get_default("sub_directory"), is_resource=False)
skip_keywords = tuple(['skip_' + k.replace('-', '_') for k in skips])
......
......@@ -30,9 +30,27 @@ extensions = [
import sphinx
if sphinx.__version__ >= "1.4.1":
extensions.append('sphinx.ext.imgmath')
imgmath_image_format = 'svg'
else:
extensions.append('sphinx.ext.pngmath')
# Be picky about warnings
nitpicky = True
# Ignores stuff we can't easily resolve on other project's sphinx manuals
nitpick_ignore = []
# Allows the user to override warnings from a separate file
if os.path.exists('nitpick-exceptions.txt'):
for line in open('nitpick-exceptions.txt'):
if line.strip() == "" or line.startswith("#"):
continue
dtype, target = line.split(None, 1)
target = target.strip()
try: # python 2.x
target = unicode(target)
except NameError:
pass
nitpick_ignore.append((dtype, target))
# Always includes todos
todo_include_todos = True
......@@ -217,7 +235,7 @@ autodoc_default_flags = [
# For inter-documentation mapping:
from bob.extension.utils import link_documentation, load_requirements
sphinx_requirements = "./extra-intersphinx.txt"
sphinx_requirements = "extra-intersphinx.txt"
if os.path.exists(sphinx_requirements):
intersphinx_mapping = link_documentation(additional_packages=load_requirements(sphinx_requirements))
else:
......
......@@ -226,7 +226,9 @@ For Bob_'s ZT-norm databases, we provide the :py:class:`bob.bio.base.database.ZT
Defining your own Database
~~~~~~~~~~~~~~~~~~~~~~~~~~
..
If you have your own database that you want to execute the recognition experiments on, you should first check if you could use the :ref:`Verifcation File List Database <bob.db.bio_filelist>` interface by defining appropriate file lists for the training set, the model set, and the probes.
If you have your own database that you want to execute the recognition experiments on, you should
first check if you could use the :ref:`Verifcation File List Database <bob.db.bio_filelist>` interface by
defining appropriate file lists for the training set, the model set, and the probes.
In most of the cases, the :py:class:`bob.db.bio_filelist.Database` should be sufficient to run experiments.
Please refer to the documentation :ref:`Documentation <bob.db.bio_filelist>` of this database for more instructions on how to configure this database.
......@@ -239,7 +241,7 @@ In this case, you have to derive your class from the :py:class:`bob.bio.base.dat
Usually, providing ids for the group ``'dev'`` should be sufficient.
* ``objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs)``
This function must return a list of ``bob.db.base.database.BioFile`` objects with your data.
This function must return a list of ``bob.bio.base.database.BioFile`` objects with your data.
The keyword arguments are possible filters that you may use.
* ``model_ids_with_protocol(self, groups, protocol, **kwargs)``
......@@ -251,10 +253,10 @@ If you don't know what ZT score normalization is, just forget about it and move
If you know and want to use it, just derive your class from :py:class:`bob.bio.base.database.ZTBioDatabase` instead, and additionally overwrite the following functions:
* ``tobjects(self, groups=None, protocol=None, model_ids=None, **kwargs)``
This function must return a list of ``bob.db.base.database.BioFile`` objects used for `T` normalization.
This function must return a list of ``bob.bio.base.database.BioFile`` objects used for `T` normalization.
* ``zobjects(self, groups=None, protocol=None, **kwargs)``
This function must return a list of ``bob.db.base.database.BioFile`` objects used for `Z` normalization.
This function must return a list of ``bob.bio.base.database.BioFile`` objects used for `Z` normalization.
* ``tmodel_ids_with_protocol(self, protocol=None, groups=None, **kwargs)``
The ids for the T norm models for the given group and protocol.
......
py:class bob.bio.video.preprocessor.Video
py:exc ValueError
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment