Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 255eb69

Browse files
author
karllab41
authored
Merge pull request #84 from CStephenson970/decorator_fix
Change dnnseparate models to run on CPU by default
2 parents 69cffd1 + b2e76f2 commit 255eb69

4 files changed

Lines changed: 50 additions & 44 deletions

File tree

src/dnnseparate/DANmodel.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
class DANModel:
77
def __init__(self, F=257, num_speakers=251,
88
layer_size=600, embedding_size=40,
9-
nonlinearity='logistic',normalize=False):
9+
nonlinearity='logistic',normalize=False,
10+
device='/cpu:0'):
1011
"""
1112
Initializes a Deep Attractor Network[i]. Default architecture is the
1213
same as for the Lab41 model and the deep clustering model.
@@ -23,6 +24,7 @@ def __init__(self, F=257, num_speakers=251,
2324
nonlinearity: Nonlinearity to use in BLSTM layers (default logistic)
2425
normalize: Do you normalize vectors coming into the final layer?
2526
(default False)
27+
device: Which device to run the model on
2628
"""
2729

2830
self.F = F
@@ -34,28 +36,28 @@ def __init__(self, F=257, num_speakers=251,
3436

3537
self.graph = tf.Graph()
3638
with self.graph.as_default():
39+
with tf.device(device):
40+
# Placeholder tensor for the magnitude spectrogram
41+
self.S = tf.placeholder("float", [None, None, self.F])
3742

38-
# Placeholder tensor for the magnitude spectrogram
39-
self.S = tf.placeholder("float", [None, None, self.F])
43+
# Placeholder tensor for the input data
44+
self.X = tf.placeholder("float", [None, None, self.F])
4045

41-
# Placeholder tensor for the input data
42-
self.X = tf.placeholder("float", [None, None, self.F])
46+
# Placeholder tensor for the labels/targets
47+
self.y = tf.placeholder("float", [None, None, self.F, None])
4348

44-
# Placeholder tensor for the labels/targets
45-
self.y = tf.placeholder("float", [None, None, self.F, None])
49+
# Placeholder for the speaker indicies
50+
self.I = tf.placeholder(tf.int32, [None,None])
4651

47-
# Placeholder for the speaker indicies
48-
self.I = tf.placeholder(tf.int32, [None,None])
49-
50-
# Define the speaker vectors to use during training
51-
self.speaker_vectors = tf_utils.weight_variable(
52+
# Define the speaker vectors to use during training
53+
self.speaker_vectors = tf_utils.weight_variable(
5254
[self.num_speakers,self.embedding_size],
5355
tf.sqrt(2/self.embedding_size))
5456

55-
# Model methods
56-
self.network
57-
self.cost
58-
self.optimizer
57+
# Model methods
58+
self.network
59+
self.cost
60+
self.optimizer
5961

6062
# Saver
6163
self.saver = tf.train.Saver()

src/dnnseparate/L41model.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
class L41Model:
77
def __init__(self, F=257, num_speakers=251,
88
layer_size=600, embedding_size=40,
9-
nonlinearity='logistic',normalize=False):
9+
nonlinearity='logistic',normalize=False,
10+
device='/cpu:0'):
1011
"""
1112
Initializes Lab41's clustering model. Default architecture comes from
1213
the parameters used by the best performing model in the paper[1].
@@ -21,8 +22,9 @@ def __init__(self, F=257, num_speakers=251,
2122
layer_size: Size of BLSTM layers
2223
embedding_size: Dimension of embedding vector
2324
nonlinearity: Nonlinearity to use in BLSTM layers (default logistic)
24-
normalize: Do you normalize vectors coming into the final layer?
25+
normalize: Do you normalize vectors coming into the final layer?
2526
(default False)
27+
device: Which device to run the model on
2628
"""
2729

2830
self.F = F
@@ -33,26 +35,27 @@ def __init__(self, F=257, num_speakers=251,
3335
self.normalize = normalize
3436

3537
self.graph = tf.Graph()
36-
with self.graph.as_default():
3738

38-
# Placeholder tensor for the input data
39-
self.X = tf.placeholder("float", [None, None, self.F])
39+
with self.graph.as_default():
40+
with tf.device(device):
41+
# Placeholder tensor for the input data
42+
self.X = tf.placeholder("float", [None, None, self.F])
4043

41-
# Placeholder tensor for the labels/targets
42-
self.y = tf.placeholder("float", [None, None, self.F, None])
44+
# Placeholder tensor for the labels/targets
45+
self.y = tf.placeholder("float", [None, None, self.F, None])
4346

44-
# Placeholder for the speaker indicies
45-
self.I = tf.placeholder(tf.int32, [None,None])
47+
# Placeholder for the speaker indicies
48+
self.I = tf.placeholder(tf.int32, [None,None])
4649

47-
# Define the speaker vectors to use during training
48-
self.speaker_vectors = tf_utils.weight_variable(
50+
# Define the speaker vectors to use during training
51+
self.speaker_vectors = tf_utils.weight_variable(
4952
[self.num_speakers,self.embedding_size],
5053
tf.sqrt(2/self.embedding_size))
5154

52-
# Model methods
53-
self.network
54-
self.cost
55-
self.optimizer
55+
# Model methods
56+
self.network
57+
self.cost
58+
self.optimizer
5659

5760
# Saver
5861
self.saver = tf.train.Saver()

src/dnnseparate/deep_clustering_model.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
class DeepClusteringModel:
77
def __init__(self, F=257,
88
layer_size=600, embedding_size=40,
9-
nonlinearity='logistic'):
9+
nonlinearity='logistic',
10+
device='/cpu:0'):
1011
"""
1112
Initializes the deep clustering model from [1]. Defaults correspond to
1213
the parameters used by the best performing model in the paper.
@@ -21,6 +22,7 @@ def __init__(self, F=257,
2122
layer_size: Size of BLSTM layers
2223
embedding_size: Dimension of embedding vector
2324
nonlinearity: Nonlinearity to use in BLSTM layers
25+
device: Which device to run the model on
2426
"""
2527

2628
self.F = F
@@ -30,17 +32,17 @@ def __init__(self, F=257,
3032

3133
self.graph = tf.Graph()
3234
with self.graph.as_default():
35+
with tf.device(device):
36+
# Placeholder tensor for the input data
37+
self.X = tf.placeholder("float", [None, None, self.F])
3338

34-
# Placeholder tensor for the input data
35-
self.X = tf.placeholder("float", [None, None, self.F])
39+
# Placeholder tensor for the labels/targets
40+
self.y = tf.placeholder("float", [None, None, self.F, None])
3641

37-
# Placeholder tensor for the labels/targets
38-
self.y = tf.placeholder("float", [None, None, self.F, None])
39-
40-
# Model methods
41-
self.network
42-
self.cost
43-
self.optimizer
42+
# Model methods
43+
self.network
44+
self.cost
45+
self.optimizer
4446

4547
# Saver
4648
self.saver = tf.train.Saver()

src/utils/tf_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ def scope_decorator(function):
1717
@functools.wraps(function)
1818
def decorator(self):
1919
if not hasattr(self,attribute):
20-
with tf.device("/cpu:0"):
21-
with tf.variable_scope(name):
22-
setattr(self,attribute,function(self))
20+
with tf.variable_scope(name):
21+
setattr(self,attribute,function(self))
2322
return getattr(self,attribute)
2423

2524
return decorator

0 commit comments

Comments
 (0)