Commit 49b8fd98 authored by Pavel KORSHUNOV's avatar Pavel KORSHUNOV
Browse files

Merge branch 'testfix'

parents 85fd5de1 ea369f80
......@@ -9,7 +9,8 @@ Presentation Attack Detection in Voice Biometrics
This package is an extension to the ``bob.pad.base`` package, which provides the basic presentation attack detection (PAD) framework.
The ``bob.pad.voice`` contains additional functionality to run PAD experiments using speech databases.
The ``bob.pad.voice`` contains additional functionality to run PAD experiments using speech databases.
Wrappers for speech databases are also included in this package.
Installation
......
......@@ -69,15 +69,15 @@ class HistDistanceAlgorithm(Algorithm):
# print ("Min attack ", numpy.min(attack_features))
# print ("Max attack ", numpy.max(attack_features))
from antispoofing.utils.ml import norm
from bob.pad.voice.utils import extraction
mean = None
std = None
# normalize features column-wise
if self.normalize_features:
mean, std = norm.calc_mean_std(real_features, attack_features, nonStdZero=True)
real_features = norm.zeromean_unitvar_norm(real_features, mean, std)
attack_features = norm.zeromean_unitvar_norm(attack_features, mean, std)
mean, std = extraction.calc_mean_std(real_features, attack_features, nonStdZero=True)
real_features = extraction.zeromean_unitvar_norm(real_features, mean, std)
attack_features = extraction.zeromean_unitvar_norm(attack_features, mean, std)
# compute average histogram for each type of features
self.real_mean = numpy.mean(real_features, axis=0)
......
......@@ -74,15 +74,15 @@ class LogRegrAlgorithm(Algorithm):
# save the trained model to file for future use
hdf5file = bob.io.base.HDF5File(projector_file, "w")
from antispoofing.utils.ml import norm
from bob.pad.voice.utils import extraction
mean = None
std = None
# reduce the feature space using PCA
if self.use_PCA_training or self.normalize_features:
mean, std = norm.calc_mean_std(real_features, attack_features, nonStdZero=True)
real_features = norm.zeromean_unitvar_norm(real_features, mean, std)
attack_features = norm.zeromean_unitvar_norm(attack_features, mean, std)
mean, std = extraction.calc_mean_std(real_features, attack_features, nonStdZero=True)
real_features = extraction.zeromean_unitvar_norm(real_features, mean, std)
attack_features = extraction.zeromean_unitvar_norm(attack_features, mean, std)
if self.use_PCA_training:
pca_trainer = bob.learn.linear.PCATrainer()
......
001 001 genuine_laptop2_sentence01 19.762860966727
001 attack attack_phone_sentence01 -11.477293810506
001 001 genuine_laptop2_sentence01 9.668502723115
001 attack attack_phone_sentence01 -27.475504915505
001 attack attack_phone_sentence01 -11.477293810506
001 attack attack_phone_sentence01 -27.475504915505
001 001 genuine_laptop2_sentence01 19.762860966727
001 001 genuine_laptop2_sentence01 9.668502723115
001 001 genuine_phone_sentence01 27.051880353577
001 attack attack_ss_sentence01 14.836701843382
001 001 genuine_phone_sentence01 16.425012903955
001 attack attack_ss_sentence01 8.957517280861
001 attack attack_ss_sentence01 14.836701843382
001 attack attack_ss_sentence01 8.957517280861
001 001 genuine_phone_sentence01 27.051880353577
001 001 genuine_phone_sentence01 16.425012903955
......@@ -68,7 +68,8 @@ def _spoof(parameters, cur_test_dir, sub_dir, score_types=('dev-real',), scores_
# assert that the data order is still correct
assert (data2check[0][:, 0:3] == data2check[1][:, 0:3]).all()
# assert that the values are OK
assert numpy.allclose(data2check[0][:, 3].astype(float), data2check[1][:, 3].astype(float), 1e-5)
print (data2check)
assert numpy.allclose(data2check[0][:, 3].astype(float), data2check[1][:, 3].astype(float), 1e-3)
finally:
shutil.rmtree(cur_test_dir)
......
......@@ -24,6 +24,48 @@ import logging
logger = logging.getLogger("bob.pad.voice")
def zeromean_unitvar_norm(data, mean, std):
""" Normalized the data with zero mean and unit variance. Mean and variance are in numpy.ndarray format"""
return numpy.divide(data - mean, std)
def calc_mean(c0, c1=[]):
""" Calculates the mean of the data."""
if c1 != []:
return (numpy.mean(c0, 0) + numpy.mean(c1, 0)) / 2.
else:
return numpy.mean(c0, 0)
def calc_std(c0, c1=[]):
""" Calculates the variance of the data."""
if c1 == []:
return numpy.std(c0, 0)
prop = float(len(c0)) / float(len(c1))
if prop < 1:
p0 = int(math.ceil(1 / prop))
p1 = 1
else:
p0 = 1
p1 = int(math.ceil(prop))
return numpy.std(numpy.vstack(p0 * [c0] + p1 * [c1]), 0)
"""
@param c0
@param c1
@param nonStdZero if the std was zero, convert to one. This will avoid a zero division
"""
def calc_mean_std(c0, c1=[], nonStdZero=False):
""" Calculates both the mean of the data. """
mi = calc_mean(c0, c1)
std = calc_std(c0, c1)
if (nonStdZero):
std[std == 0] = 1
return mi, std
def vad_filter_features(vad_labels, features, filter_frames="trim_silence"):
""" Trim the spectrogram to remove silent head/tails from the speech sample.
Keep all remaining frames or either speech or non-speech only
......@@ -69,7 +111,7 @@ def vad_filter_features(vad_labels, features, filter_frames="trim_silence"):
elif filter_frames == "speech_only":
filtered_features = features[speech, :]
else: # when we take all
filtered_features = features[nzstart:nzend+1, :] # numpy slicing is a non-closed interval [)
filtered_features = features[nzstart:nzend + 1, :] # numpy slicing is a non-closed interval [)
else:
logger.error("vad_filter_features(): VAD labels should be the same length as energy bands")
......
......@@ -4,13 +4,22 @@
[buildout]
parts = scripts
eggs = gridtk
eggs = bob.pad.voice
bob.bio.spear
bob.pad.base
bob.bio.base
bob.db.base
gridtk
extensions = bob.buildout
mr.developer
auto-checkout = *
develop = .
develop = src/bob.bio.spear
src/bob.pad.base
src/bob.bio.base
src/bob.db.base
.
; options for bob.buildout
debug = true
......@@ -18,6 +27,10 @@ verbose = true
newest = false
[sources]
bob.bio.spear = git git@gitlab.idiap.ch:bob/bob.bio.spear.git
bob.db.base = git git@gitlab.idiap.ch:bob/bob.db.base.git
bob.bio.base = git git@gitlab.idiap.ch:bob/bob.bio.base.git
bob.pad.base = git git@gitlab.idiap.ch:bob/bob.pad.base.git
[scripts]
recipe = bob.buildout:scripts
......
......@@ -44,7 +44,7 @@ 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
bob.bio.base = git git@gitlab.idiap.ch:bob/bob.bio.base.git
bob.pad.base = git branch=move-pad-db-definition-here git@gitlab.idiap.ch:bob/bob.pad.base.git
bob.pad.base = git git@gitlab.idiap.ch:bob/bob.pad.base.git
bob.ap = git git@github.com:pkorshunov/bob.ap.git
[scripts]
......
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