Skip to content

Commit e2940c7

Browse files
committed
fix variable scope error for Stack LSTM
1 parent 440d3e0 commit e2940c7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

09_Recurrent_Neural_Networks/04_Stacking_Multiple_LSTM_Layers/04_stacking_multiple_lstm.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ def sample(self, sess, words=ix2vocab, vocab=vocab2ix, num=20, prime_text='thou
197197
out_sentence = out_sentence + char
198198
return(out_sentence)
199199

200-
with tf.variable_scope('lstm_model') as scope:
201-
# Define LSTM Model
202-
lstm_model = LSTM_Model(rnn_size, num_layers, batch_size, learning_rate,
203-
training_seq_len, vocab_size)
204-
scope.reuse_variables()
205-
test_lstm_model = LSTM_Model(rnn_size, num_layers, batch_size, learning_rate,
206-
training_seq_len, vocab_size, infer_sample=True)
207200

201+
# Define LSTM Model
202+
lstm_model = LSTM_Model(rnn_size, num_layers, batch_size, learning_rate,
203+
training_seq_len, vocab_size)
204+
205+
# Tell TensorFlow we are reusing the scope for the testing
206+
with tf.variable_scope(tf.get_variable_scope(), reuse=True):
207+
test_lstm_model = LSTM_Model(rnn_size,num_layers, batch_size, learning_rate,
208+
training_seq_len, vocab_size, infer_sample=True)
208209

209210
# Create model saver
210211
saver = tf.train.Saver(tf.global_variables())

0 commit comments

Comments
 (0)