'How to updata the state of LSTM using tensorflow 1.X?

I am writing a LSTM network recently.There always a question confuse me. When I use a placeholder as a input of graph, how can I initialize the state of LSTM? Because of the dynamic shape of place holder(like batch size of the data)I don't know how to initialize hidden state dynamically with batch size through graph.

Input data like this:

input_seq = tf.compat.v1.placeholder(dtype=tf.float32,shape=\[2,None,3\])#time_step=2,batch_size=None

Input first time step:

seq = input_seq\[0\]

I'd like to set the hidden state as follows:

self.hidden_state = tf.zeros_like(tf.compat.v1.placeholder(dtype=tf.float32,shape=\[seq.get_shape()\[1\],self.hidden_dims\]))

I's all right before I execute the graph. But when I flow the graph, I have to feed the hidden state placeholder. So I'm finding a method don't to do this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source