Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.pad.voice
Commits
5b428b7c
Commit
5b428b7c
authored
Dec 10, 2017
by
Pavel KORSHUNOV
Browse files
upgraded voice evaluation with TF
parent
55fd8a26
Pipeline
#14711
passed with stages
in 17 minutes and 13 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
bob/pad/voice/algorithm/
LSTM
Eval.py
→
bob/pad/voice/algorithm/
Tensorflow
Eval.py
View file @
5b428b7c
...
...
@@ -14,12 +14,13 @@ import logging
logger
=
logging
.
getLogger
(
"bob.pad.voice"
)
class
LSTM
Eval
(
Algorithm
):
class
Tensorflow
Eval
(
Algorithm
):
"""This class is for evaluating data stored in tensorflow tfrecord format using a pre-trained LSTM model."""
def
__init__
(
self
,
architecture_name
=
"mlp"
,
input_shape
=
[
200
,
81
],
# [temporal_length, feature_size]
lstm_
network_size
=
60
,
# the output size of LSTM cell
network_size
=
60
,
# the output size of LSTM cell
normalization_file
=
None
,
# file with normalization parameters from train set
**
kwargs
):
"""Generates a test value that is read and written"""
...
...
@@ -32,17 +33,19 @@ class LSTMEval(Algorithm):
**
kwargs
)
self
.
architecture_name
=
architecture_name
self
.
input_shape
=
input_shape
self
.
num_time_steps
=
input_shape
[
0
]
self
.
lstm_
network_size
=
lstm_
network_size
self
.
network_size
=
network_size
self
.
data_std
=
None
# import ipdb
# ipdb.set_trace()
features_length
=
input_shape
[
1
]
if
normalization_file
and
os
.
path
.
exists
(
normalization_file
):
logger
.
info
(
"Loading normalization file '%s' "
%
normalization_file
)
npzfile
=
numpy
.
load
(
normalization_file
)
self
.
data_mean
=
npzfile
[
'data_mean'
]
self
.
data_std
=
npzfile
[
'data_std'
]
self
.
data_std
=
numpy
.
array
(
npzfile
[
'data_std'
]
)
if
not
self
.
data_std
.
shape
:
# if std was saved as scalar
self
.
data_std
=
numpy
.
ones
(
features_length
)
# if self.data_mean.shape[0] > input_shape[0]:
...
...
@@ -52,6 +55,7 @@ class LSTMEval(Algorithm):
# self.data_std = self.data_std[:input_shape[0]]
# self.data_std = numpy.reshape(self.data_std, input_shape)
else
:
logger
.
warn
(
"Normalization file '%s' does not exist!"
%
normalization_file
)
self
.
data_mean
=
0
self
.
data_std
=
1
...
...
@@ -60,29 +64,29 @@ class LSTMEval(Algorithm):
self
.
dnn_model
=
None
self
.
data_placeholder
=
None
def
simple_lstm_network
(
self
,
train_data_shuffler
,
batch_size
=
10
,
lstm_cell_size
=
64
,
num_time_steps
=
28
,
num_classes
=
10
,
seed
=
10
,
reuse
=
False
):
import
tensorflow
as
tf
from
bob.learn.tensorflow.layers
import
lstm
slim
=
tf
.
contrib
.
slim
if
isinstance
(
train_data_shuffler
,
tf
.
Tensor
):
inputs
=
train_data_shuffler
else
:
inputs
=
train_data_shuffler
(
"data"
,
from_queue
=
False
)
initializer
=
tf
.
contrib
.
layers
.
xavier_initializer
(
seed
=
seed
)
# Creating an LSTM network
graph
=
lstm
(
inputs
,
lstm_cell_size
,
num_time_steps
=
num_time_steps
,
batch_size
=
batch_size
,
output_activation_size
=
num_classes
,
scope
=
'lstm'
,
name
=
'sync_cell'
,
weights_initializer
=
initializer
,
activation
=
tf
.
nn
.
sigmoid
,
reuse
=
reuse
)
# fully connect the LSTM output to the classes
graph
=
slim
.
fully_connected
(
graph
,
num_classes
,
activation_fn
=
None
,
scope
=
'fc1'
,
weights_initializer
=
initializer
,
reuse
=
reuse
)
return
graph
#
def simple_lstm_network(self, train_data_shuffler, batch_size=10, lstm_cell_size=64,
#
num_time_steps=28, num_classes=10, seed=10, reuse=False):
#
import tensorflow as tf
#
from bob.learn.tensorflow.layers import lstm
#
slim = tf.contrib.slim
#
#
if isinstance(train_data_shuffler, tf.Tensor):
#
inputs = train_data_shuffler
#
else:
#
inputs = train_data_shuffler("data", from_queue=False)
#
#
initializer = tf.contrib.layers.xavier_initializer(seed=seed)
#
#
# Creating an LSTM network
#
graph = lstm(inputs, lstm_cell_size, num_time_steps=num_time_steps, batch_size=batch_size,
#
output_activation_size=num_classes, scope='lstm', name='sync_cell',
#
weights_initializer=initializer, activation=tf.nn.sigmoid, reuse=reuse)
#
#
# fully connect the LSTM output to the classes
#
graph = slim.fully_connected(graph, num_classes, activation_fn=None, scope='fc1',
#
weights_initializer=initializer, reuse=reuse)
#
#
return graph
def
normalize_data
(
self
,
features
):
mean
=
numpy
.
mean
(
features
,
axis
=
0
)
...
...
@@ -97,16 +101,34 @@ class LSTMEval(Algorithm):
def
restore_trained_model
(
self
,
projector_file
):
import
tensorflow
as
tf
from
bob.learn.tensorflow.network
import
LightCNN9
if
self
.
session
is
None
:
self
.
session
=
tf
.
Session
()
data_pl
=
tf
.
placeholder
(
tf
.
float32
,
shape
=
(
None
,)
+
tuple
(
self
.
input_shape
),
name
=
"data"
)
# network = LightCNN9(n_classes=2, device="/cpu:0")
# graph = network(data_pl)
graph
=
self
.
simple_lstm_network
(
data_pl
,
batch_size
=
1
,
lstm_cell_size
=
self
.
lstm_network_size
,
num_time_steps
=
self
.
num_time_steps
,
num_classes
=
2
,
reuse
=
False
)
# create an empty graph of the correct architecture but with needed batch_size==1
if
self
.
architecture_name
==
'lstm'
:
from
bob.learn.tensorflow.network
import
simple_lstm_network
graph
=
simple_lstm_network
(
data_pl
,
batch_size
=
1
,
lstm_cell_size
=
self
.
network_size
,
num_time_steps
=
self
.
num_time_steps
,
num_classes
=
2
,
reuse
=
False
)
elif
self
.
architecture_name
==
'mlp'
:
from
bob.learn.tensorflow.network
import
mlp_network
graph
=
mlp_network
(
data_pl
,
hidden_layer_size
=
self
.
network_size
,
num_time_steps
=
self
.
num_time_steps
,
num_classes
=
2
,
reuse
=
False
)
elif
self
.
architecture_name
==
'simplecnn'
:
from
bob.learn.tensorflow.network
import
simple2Dcnn_network
graph
=
simple2Dcnn_network
(
data_pl
,
num_classes
=
2
,
reuse
=
False
)
elif
self
.
architecture_name
==
'lightcnn'
:
from
bob.learn.tensorflow.network
import
LightCNN9
network
=
LightCNN9
(
n_classes
=
2
,
device
=
"/cpu:0"
)
graph
=
network
(
data_pl
,
reuse
=
False
)
else
:
return
None
self
.
session
.
run
(
tf
.
global_variables_initializer
())
saver
=
tf
.
train
.
Saver
()
...
...
@@ -201,4 +223,4 @@ class LSTMEval(Algorithm):
return
[
toscore
[
0
]]
algorithm
=
LSTM
Eval
()
algorithm
=
Tensorflow
Eval
()
bob/pad/voice/algorithm/__init__.py
View file @
5b428b7c
from
.GMM
import
GMM
from
.LogRegr
import
LogRegr
from
.
LSTM
Eval
import
LSTM
Eval
from
.
Tensorflow
Eval
import
Tensorflow
Eval
# gets sphinx autodoc done right - don't remove it
def
__appropriate__
(
*
args
):
...
...
@@ -19,6 +19,6 @@ def __appropriate__(*args):
__appropriate__
(
GMM
,
LogRegr
,
LSTM
Eval
,
Tensorflow
Eval
,
)
__all__
=
[
_
for
_
in
dir
()
if
not
_
.
startswith
(
'_'
)]
develop.cfg
View file @
5b428b7c
...
...
@@ -13,6 +13,7 @@ eggs = bob.pad.voice
bob.pad.base
bob.db.asvspoof
bob.db.avspoof
bob.learn.tensorflow
gridtk
extensions = bob.buildout
...
...
@@ -26,6 +27,8 @@ develop = src/bob.bio.spear
src/bob.db.avspoof
src/bob.bio.base
src/bob.pad.base
bob.learn.tensorflow
/remote/idiap.svm/home.active/pkorshunov/src/bob.learn.tensorflow
.
; options for bob.buildout
...
...
@@ -41,6 +44,7 @@ bob.db.asvspoof = git git@gitlab.idiap.ch:bob/bob.db.asvspoof.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
bob.bio.spear = git git@gitlab.idiap.ch:bob/bob.bio.spear.git
bob.learn.tensorflow = fs bob.learn.tensorflow full-path=/remote/idiap.svm/home.active/pkorshunov/src/bob.learn.tensorflow
[scripts]
recipe = bob.buildout:scripts
...
...
setup.py
View file @
5b428b7c
...
...
@@ -116,7 +116,7 @@ setup(
],
'bob.pad.algorithm'
:
[
'tensorflow = bob.pad.voice.algorithm.
LSTM
Eval:algorithm'
,
'tensorflow = bob.pad.voice.algorithm.
Tensorflow
Eval:algorithm'
,
'dummy-algo = bob.pad.voice.algorithm.dummy:algorithm'
,
# compute scores based on different energy bands
'logregr = bob.pad.voice.algorithm.LogRegr:algorithm'
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment