0

I am a novice trying to learn Tensorflow 2.0 for a neural network.

Currently, I am stuck on the following error: 'StackedRNNCells' object has no attribute 'zero_state'.

My code:

#Preparing the data for training and testing
S_T = self.S_t_input[-1,:,0]
dS = self.S_t_input[1:, :, 0] - self.S_t_input[0:-1, :, 0]
S_t = tf.unstack(self.S_t_input[:-1, :,:], axis=0, num=2)
    
# Build the lstm
lstm = tf.keras.layers.StackedRNNCells([tf.keras.layers.LSTMCell(n) for n in nodes])
self.strategy, state = tf.keras.layers.RNN(lstm, S_t, initial_state=lstm.zero_state(batch_size, dtype=tf.dtypes.float32), dtype=tf.dtypes.float32)

My code is inspired by previous work conducted in Tensorflow 1.5. I tried to use get_initial_state, which resulted in even more error messages.

qfint
  • 1
  • You might find [this](https://stackoverflow.com/questions/52866449/tensorflow-rnn-how-to-create-zero-state-with-various-batch-size) relevant – Aditya Mishra Jul 22 '20 at 18:25
  • It is my impression that placeholder does not exist in TF 2.0, but I still tried to implement that solution, however it resulted in the same error message. Thank you! – qfint Jul 22 '20 at 18:29

0 Answers0