Skip to content

Commit 6ce97be

Browse files
committedMar 14, 2017
update code for tf version > 1.0
1 parent bffeefe commit 6ce97be

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎tensorflowTUT/tf20_RNN2/full_code.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ def RNN(X, weights, biases):
6565
##########################################
6666

6767
# basic LSTM Cell.
68-
lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden_units, forget_bias=1.0, state_is_tuple=True)
68+
if int((tf.__version__).split('.')[1]) < 12 and int((tf.__version__).split('.')[0]) < 1:
69+
lstm_cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden_units, forget_bias=1.0, state_is_tuple=True)
70+
else:
71+
lstm_cell = tf.contrib.rnn.BasicLSTMCell(n_hidden_units)
6972
# lstm cell is divided into two parts (c_state, h_state)
7073
init_state = lstm_cell.zero_state(batch_size, dtype=tf.float32)
7174

@@ -85,14 +88,17 @@ def RNN(X, weights, biases):
8588

8689
# # or
8790
# unpack to list [(batch, outputs)..] * steps
88-
outputs = tf.unpack(tf.transpose(outputs, [1, 0, 2])) # states is the last outputs
91+
if int((tf.__version__).split('.')[1]) < 12 and int((tf.__version__).split('.')[0]) < 1:
92+
outputs = tf.unpack(tf.transpose(outputs, [1, 0, 2])) # states is the last outputs
93+
else:
94+
outputs = tf.unstack(tf.transpose(outputs, [1,0,2]))
8995
results = tf.matmul(outputs[-1], weights['out']) + biases['out']
9096

9197
return results
9298

9399

94100
pred = RNN(x, weights, biases)
95-
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
101+
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))
96102
train_op = tf.train.AdamOptimizer(lr).minimize(cost)
97103

98104
correct_pred = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))

0 commit comments

Comments
 (0)
Please sign in to comment.