Commit c9ebba67 authored by Pavel KORSHUNOV's avatar Pavel KORSHUNOV

Added suport for ASVspoof2017 competition DB. Updated bootstraping.

parent ce0078af
Pipeline #6940 failed with stages
in 25 minutes and 33 seconds
#!/usr/bin/env python
import bob.pad.voice.database
# directory where the wave files are stored
asvspoof_input_dir = "/idiap/group/biometric/databases/pad/ASVspoof2017/ASVspoof2017_train_dev"
asvspoof_input_ext = ".wav"
database = bob.pad.voice.database.ASVspoof2017PadDatabase(
protocol='competition',
original_directory=asvspoof_input_dir,
original_extension=asvspoof_input_ext,
training_depends_on_protocol=True,
)
from .database import PadVoiceFile
from .asvspoof import ASVspoofPadDatabase
from .asvspoof2017 import ASVspoof2017PadDatabase
from .avspoof import AVspoofPadDatabase
from .replay import ReplayPadDatabase
from .replaymobile import ReplayMobilePadDatabase
......@@ -28,5 +29,6 @@ __appropriate__(
ReplayMobilePadDatabase,
VoicePAPadDatabase,
CPqDReplayPadDatabase,
ASVspoof2017PadDatabase,
)
__all__ = [_ for _ in dir() if not _.startswith('_')]
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Pavel Korshunov <pavel.korshunov@idiap.ch>
# Fri 3 Feb 13:43:22 2017
"""
This is a high level interface for presentation attack ASVspoof2017 database.
It is an extension of an interface defined inside bob.pad.base PAD framework.
"""
from bob.pad.voice.database import PadVoiceFile
from bob.pad.base.database import PadDatabase
class ASVspoof2017PadFile(PadVoiceFile):
def __init__(self, f):
"""
Initializes this File object with an File equivalent from the underlying SQl-based interface for
ASVspoof2017 database.
"""
attacktype = None
if f.is_attack():
attacktype = str(f.attacktype)
super(ASVspoof2017PadFile, self).__init__(client_id=f.client_id, path=f.path, attack_type=attacktype, file_id=f.id)
self.__f = f
class ASVspoof2017PadDatabase(PadDatabase):
"""
Implements verification API for querying ASVspoof2017 database.
"""
def __init__(self, protocol='competition', **kwargs):
# call base class constructors to open a session to the database
PadDatabase.__init__(self, name='asvspoof2017', protocol=protocol, **kwargs)
from bob.db.asvspoof2017.query import Database as LowLevelDatabase
self.__db = LowLevelDatabase()
def convert_purposes(self, names, low_level_names, high_level_names):
"""
Converts purposes names from a low level to high level API
"""
if names is None:
return None
mapping = dict(zip(low_level_names, high_level_names))
if isinstance(names, str):
return mapping.get(names)
return [mapping[g] for g in names]
def objects(self, groups=None, protocol=None, purposes=None, model_ids=None, **kwargs):
"""Returns a set of Files for the specific query by the user.
Keyword Parameters:
groups
One of the groups ('dev', 'eval', 'train') or a tuple with several of them.
If 'None' is given (this is the default), it is considered the same as a
tuple with all possible values.
protocol
The protocol for which the clients should be retrieved.
The protocol is dependent on your database.
If you do not have protocols defined, just ignore this field.
purposes
The purposes can be either 'real' or 'attack'.
model_ids
This parameter is not supported in this implementation.
Returns: A set of Files with the specified properties.
"""
purposes = self.convert_purposes(purposes, ('genuine', 'spoof'), ('real', 'attack'))
objects = self.__db.objects(protocol=protocol, groups=groups, purposes=purposes, **kwargs)
return [ASVspoof2017PadFile(f) for f in objects]
......@@ -25,7 +25,10 @@ import tempfile
from optparse import OptionParser
tmpeggs = tempfile.mkdtemp()
__version__ = '2015-07-01'
# See zc.buildout's changelog if this version is up to date.
tmpeggs = tempfile.mkdtemp(prefix='bootstrap-')
usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
......@@ -40,8 +43,9 @@ this script from going over the network.
'''
parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", help="use a specific zc.buildout version")
parser.add_option("--version",
action="store_true", default=False,
help=("Return bootstrap.py version."))
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
......@@ -59,25 +63,33 @@ parser.add_option("-f", "--find-links",
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--buildout-version",
help="Use a specific zc.buildout version")
parser.add_option("--setuptools-version",
help="use a specific setuptools version")
help="Use a specific setuptools version")
parser.add_option("--setuptools-to-dir",
help=("Allow for re-use of existing directory of "
"setuptools versions"))
options, args = parser.parse_args()
if options.version:
print("bootstrap.py version %s" % __version__)
sys.exit(0)
######################################################################
# load/install setuptools
try:
if options.allow_site_packages:
import setuptools
import pkg_resources
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
ez = {}
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
if os.path.exists('ez_setup.py'):
exec(open('ez_setup.py').read(), ez)
else:
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
......@@ -88,12 +100,19 @@ if not options.allow_site_packages:
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]
# Strip all site-packages directories from sys.path that
# are not sys.prefix; this is because on Windows
# sys.prefix is a site-package directory.
if sitepackage_path != sys.prefix:
sys.path[:] = [x for x in sys.path
if sitepackage_path not in x]
setup_args = dict(to_dir=tmpeggs, download_delay=0)
if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version
if options.setuptools_to_dir is not None:
setup_args['to_dir'] = options.setuptools_to_dir
ez['use_setuptools'](**setup_args)
import setuptools
......@@ -110,7 +129,12 @@ for path in sys.path:
ws = pkg_resources.working_set
setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location
# Fix sys.path here as easy_install.pth added before PYTHONPATH
cmd = [sys.executable, '-c',
'import sys; sys.path[0:0] = [%r]; ' % setuptools_path +
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]
......@@ -123,11 +147,8 @@ find_links = os.environ.get(
if find_links:
cmd.extend(['-f', find_links])
setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location
requirement = 'zc.buildout'
version = options.version
version = options.buildout_version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
......@@ -167,7 +188,7 @@ if version:
cmd.append(requirement)
import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
if subprocess.call(cmd) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])
......
......@@ -14,6 +14,7 @@ eggs = bob.pad.voice
bob.measure
bob.ap
bob.db.asvspoof
bob.db.asvspoof2017
bob.db.avspoof
bob.db.voicepa
bob.extension
......@@ -29,6 +30,7 @@ extensions = bob.buildout
auto-checkout = *
develop = src/bob.bio.spear
src/bob.bio.gmm
src/bob.db.asvspoof2017
src/bob.db.asvspoof
src/bob.db.avspoof
src/bob.db.voicepa
......@@ -50,6 +52,7 @@ newest = false
[sources]
bob.bio.gmm = git git@gitlab.idiap.ch:bob/bob.bio.gmm.git
bob.db.asvspoof2017 = git git@gitlab.idiap.ch:bob/bob.db.asvspoof2017.git
bob.db.avspoof = git git@gitlab.idiap.ch:bob/bob.db.avspoof.git
bob.db.asvspoof = git git@gitlab.idiap.ch:bob/bob.db.asvspoof.git
bob.db.base = git git@gitlab.idiap.ch:bob/bob.db.base.git
......
......@@ -113,6 +113,7 @@ setup(
'asvspoof = bob.pad.voice.config.database.asvspoof:database',
'voicepa = bob.pad.voice.config.database.voicepa:database',
'cpqd_replay = bob.pad.voice.config.database.cpqd_replay:database',
'asvspoof2017 = bob.pad.voice.config.database.asvspoof2017:database',
],
'bob.pad.algorithm': [
......
......@@ -4,4 +4,5 @@ bob.measure
bob.db.asvspoof
bob.db.avspoof
bob.db.voicepa
bob.db.cpqd_replay
\ No newline at end of file
bob.db.cpqd_replay
bob.db.asvspoof2017
\ No newline at end of file
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