Commit f4f3bb3a by André Anjos

Open-source release

parents
*~
*.swp
*.pyc
bin
eggs
parts
build
.installed.cfg
*.egg-info
develop-eggs
sphinx
dist
.nfs*
*.egg
.coverage
*.aux
*.bbl
*.blg
*.log
*.out
*.vrb
*.nav
*.snm
*.toc
.~lock.*
*.pyg
.DS_Store
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.web module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
===========================================================
Authors of the Biometrics Evaluation and Testing Platform
===========================================================
Andre Anjos <andre.anjos@idiap.ch>
Flavio Tarsetti <flavio.tarsetti@idiap.ch>
Laurent El-Shafey <laurent.el-shafey@idiap.ch>
Philip Abbet <philip.abbet@idiap.ch>
Samuel Gaist <samuel.gaist@idiap.ch>
Sebastien Marcel <sebastien.marcel@idiap.ch>
This diff is collapsed. Click to expand it.
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
====================
BEAT Contributions
====================
This package contains a set of contributions for different domains to which the
BEAT platform is applicable. It contains databases, dataformats, algorithms,
experiments and toolchain definitions for a variety of experiments.
Installation
------------
Include this package into your ``buildout.cfg`` to make use of it. Use
``mr.developer`` to fetch it from `our git repository`_.
Support
-------
For support, contact the platform developers through `our mailing list`_.
.. External links
.. _our mailing list: https://groups.google.com/forum/#!forum/beat-devel
.. _our git repository: https://gitlab.idiap.ch/biometric/beat.databases.git
{
"parameters": {
"radius": {
"default": 1,
"type": "uint32",
"description": "LBP radius in pixels"
},
"num-neighbors": {
"default": 8,
"type": "uint32",
"description": "Number of points to be used for the LBP operator"
}
},
"language": "python",
"uses": {},
"groups": [
{
"inputs": {
"input_frames": {
"type": "system/array_3d_uint8/1"
}
},
"name": "main",
"outputs": {
"lbp_feature_vector": {
"type": "system/array_1d_floats/1"
}
}
}
],
"splittable": true,
"description": "Computes normalized LBP histogram, averaged over frames of the video"
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
import bob.ip.base
class Algorithm:
def __init__(self):
self.radius = 1
self.num_neighbors = 8
def setup(self, parameters):
self.radius = int(parameters.get('radius', self.radius))
self.num_neighbors = int(parameters.get('num-neighbors', self.num_neighbors))
return True
def process(self, inputs, outputs):
frames = inputs["input_frames"].data.value
lbp = bob.ip.base.LBP(neighbors=self.num_neighbors, uniform=True, circular=True, radius=self.radius)
feat_vector = numpy.zeros(lbp.max_label, dtype='float64')
for i in range(frames.shape[0]):
frame = frames[0]
lbpimage = numpy.zeros(lbp.get_lbp_shape(frame), 'uint16') # allocating the image with lbp codes
lbp(frame, lbpimage) # calculating the lbp image
hist = bob.ip.base.histogram(lbpimage, 0, lbp.max_label-1, lbp.max_label)
hist = hist / sum(hist)
feat_vector = feat_vector + hist
feat_vector = feat_vector / frames.shape[0]
outputs["lbp_feature_vector"].write({
'value': feat_vector,
})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm computes LBP-based feature vector. For a given input set of frames in a video,
it computes the normalized LBP histogram. Then, it computes the final feature vector on video
level, by averaging the normalized LBP histograms.
The used LBP operator is computed over a circular neighborhood and is uniform.
Details about LBP operator can be found in [Ojala02]_
This algorithm relies on the `Bob <http://www.idiap.ch/software/bob>`_ library.
.. [Ojala02] Ojala, Pietikainen and Maenpaa: Multiresolution gray-scale and rotation invariant texture classification with Local Binary Patterns. IEEE Transactions on Pattern Analysis and Machine inteligence 2002
{
"description": "Implements the Linear and Mel Frequency Cepstal Coefficients (MFCC and LFCC)",
"language": "python",
"splittable": true,
"groups": [
{
"inputs": {
"speech": {
"type": "{{ system_user.username }}/array_1d_floats/1"
},
"vad": {
"type": "{{ system_user.username }}/array_1d_integers/1"
}
},
"outputs": {
"features": {
"type": "{{ system_user.username }}/array_2d_floats/1"
}
}
}
],
"parameters": {
"rate": {
"default": "16000.0",
"type": "float64",
"description": "sampling rate"
}
}
}
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
import bob.ap
def normalize_std_array(vector):
"""Applies a unit mean and variance normalization to an arrayset"""
# Initializes variables
length = 1
n_samples = len(vector)
mean = numpy.ndarray((length,), 'float64')
std = numpy.ndarray((length,), 'float64')
mean.fill(0)
std.fill(0)
# Computes mean and variance
for array in vector:
x = array.astype('float64')
mean += x
std += (x ** 2)
mean /= n_samples
std /= n_samples
std -= (mean ** 2)
std = std ** 0.5
arrayset = numpy.ndarray(shape=(n_samples,mean.shape[0]), dtype=numpy.float64)
for i in range (0, n_samples):
arrayset[i,:] = (vector[i]-mean) / std
return arrayset
class Algorithm:
def __init__(self):
self.win_length_ms = 20
self.win_shift_ms = 10
self.n_filters = 24
self.n_ceps = 19
self.f_min = 0
self.f_max = 4000
self.delta_win = 2
self.pre_emphasis_coef = 0.95
self.dct_norm = False
self.mel_scale = True
self.withEnergy = True
self.withDelta = True
self.withDeltaDelta = True
#TODO: find a way to compute this automatically
self.rate = 16000
self.features_mask = numpy.arange(0,60)
self.normalizeFeatures = True
def setup(self, parameters):
self.rate = parameters.get('rate', self.rate)
wl = self.win_length_ms
ws = self.win_shift_ms
nf = self.n_filters
nc = self.n_ceps
f_min = self.f_min
f_max = self.f_max
dw = self.delta_win
pre = self.pre_emphasis_coef
rate = self.rate
normalizeFeatures = self.normalizeFeatures
self.extractor = bob.ap.Ceps(rate, wl, ws, nf, nc, f_min, f_max, dw, pre)
self.extractor.dct_norm = self.dct_norm
self.extractor.mel_scale = self.mel_scale
self.extractor.with_energy = self.withEnergy
self.extractor.with_delta = self.withDelta
self.extractor.with_delta_delta = self.withDeltaDelta
return True
def normalize_features(self, params):
#########################
## Initialisation part ##
#########################
normalized_vector = [ [ 0 for i in range(params.shape[1]) ] for j in range(params.shape[0]) ]
for index in range(params.shape[1]):
vector = numpy.array([row[index] for row in params])
n_samples = len(vector)
norm_vector = normalize_std_array(vector)
for i in range(n_samples):
normalized_vector[i][index]=numpy.asscalar(norm_vector[i])
data = numpy.array(normalized_vector)
return data
def process(self, inputs, outputs):
float_wav = inputs["speech"].data.value
labels = inputs["vad"].data.value
cepstral_features = self.extractor(float_wav)
features_mask = self.features_mask
filtered_features = numpy.ndarray(shape=((labels == 1).sum(),len(features_mask)), dtype=numpy.float64)
i=0
cur_i=0
for row in cepstral_features:
if i < len(labels):
if labels[i]==1:
for k in range(len(features_mask)):
filtered_features[cur_i,k] = row[features_mask[k]]
cur_i = cur_i + 1
i = i+1
else:
if labels[-1]==1:
if cur_i == cepstral_features.shape[0]:
for k in range(len(features_mask)):
filtered_features[cur_i,k] = row[features_mask[k]]
cur_i = cur_i + 1
i = i+1
if self.normalizeFeatures:
normalized_features = self.normalize_features(filtered_features)
else:
normalized_features = filtered_features
if normalized_features.shape[0] == 0:
#print("Warning: no speech found in: %s" % input_file)
# But do not keep it empty!!! This avoids errors in next steps
normalized_features=numpy.array([numpy.zeros(len(features_mask))])
outputs["features"].write({
'value': numpy.vstack(normalized_features)
})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..
.. accordance with the terms contained in a written agreement between you ..
.. and Idiap. For further information contact tto@idiap.ch ..
.. ..
.. Alternatively, this file may be used under the terms of the GNU Affero ..
.. Public License version 3 as published by the Free Software and appearing ..
.. in the file LICENSE.AGPL included in the packaging of this file. ..
.. The BEAT platform is distributed in the hope that it will be useful, but ..
.. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ..
.. or FITNESS FOR A PARTICULAR PURPOSE. ..
.. ..
.. You should have received a copy of the GNU Affero Public License along ..
.. with the BEAT platform. If not, see http://www.gnu.org/licenses/. ..
This algorithm implements Mel-frequency cepstral coefficients (MFCC) and
linear-frequency cepstral coefficients (LFCC) feature extraction.
This algorithm relies on the `Bob <http://www.idiap.ch/software/bob/>`_ library.
The following parameters are set inside the algorithm and could be modified by forking
this algorithm:
* `win_length_ms`: length of the processing window
* `win_shift_ms`: length of the shift
* `n_filters`: number of filters
* `n_ceps`: number of cepstal coefficients
* `f_min`: minimum frequency
* `f_max`: maximum frequency
* `delta_win`: window on which first and second derivatives are computed
* `pre_emphasis_coeff`: pre-emphasis coefficient
* `mel_scale`: flag for Mel scale
* `dct_norm`: DCT normalization
* `with_delta`: flag for computing the first derivatives
* `with_delta_delta`: flag for computing the second derivatives
* `with_energy`: flag for computing the energy
* `features_mask`: mask to use only a sub-set of features
* `normalizeFeatures`: flag to do zero-mean and variance normalization
{
"parameters": {},
"language": "python",
"uses": {},
"groups": [
{
"inputs": {
"feature_vectors": {
"type": "system/array_1d_floats/1"
}
},
"name": "probes",
"outputs": {
"scores": {
"type": "system/float/1"
}
}
},
{
"inputs": {
"machine": {
"type": "system/array_1d_floats/1"
}
},
"name": "train"
}
],
"splittable": true,
"description": "Compares a histogram to a histogram model using a Chi-2 distance"
}
\ No newline at end of file
###############################################################################
# #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ #
# Contact: beat.support@idiap.ch #
# #
# This file is part of the beat.examples module of the BEAT platform. #
# #
# Commercial License Usage #
# Licensees holding valid commercial BEAT licenses may use this file in #
# accordance with the terms contained in a written agreement between you #
# and Idiap. For further information contact tto@idiap.ch #
# #
# Alternatively, this file may be used under the terms of the GNU Affero #
# Public License version 3 as published by the Free Software and appearing #
# in the file LICENSE.AGPL included in the packaging of this file. #
# The BEAT platform is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. #
# #
# You should have received a copy of the GNU Affero Public License along #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/. #
# #
###############################################################################
import numpy
class Algorithm:
def __init__(self):
self.data = []
self.machine = None
def process(self, inputs, outputs):
if self.machine == None:
inputs['machine'].next()
self.machine = inputs["machine"].data.value
sample = inputs['feature_vectors'].data.value
tmp = numpy.square(sample - self.machine)
tmp = numpy.nan_to_num(numpy.divide(tmp, self.machine))
score = -numpy.sum(tmp)
outputs["scores"].write({'value': score})
return True
.. Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ ..
.. Contact: beat.support@idiap.ch ..
.. ..
.. This file is part of the beat.examples module of the BEAT platform. ..
.. ..
.. Commercial License Usage ..
.. Licensees holding valid commercial BEAT licenses may use this file in ..