<p>The state for LSTMs really consists of two parts</p>

<ol>
<li>State for the cell(s)</li>
<li>Previous outputs</li>
</ol>

<p>This is alluded to in <a href="https://www.tensorflow.org/api_docs/python/tf/contrib/rnn/BasicLSTMCell" rel="nofollow noreferrer">the docs</a> for BasicLSTMCell. <a href="https://arxiv.org/pdf/1503.04069.pdf" rel="nofollow noreferrer">This paper</a> has a good explanation of how LSTMs work which will help you understand why you need to keep two sets of states in an LSTM implementation. The reason an error is being thrown is because you need to supply a tuple of tensors for the initial state.</p>

<p>That said you have two options:</p>

<ol>
<li>Supply an initial state that consists of two tensors.</li>
<li>Let the RNN cell generate its own initial state.</li>
</ol>

<p>You would usually only do 1. if you wanted to override default behavior. In this case you are using the default (zero) initial state so you can do 2.</p>

<pre><code>lstm_outputs, final_state = tf.nn.dynamic_rnn(cell=lstm, inputs=lstm_inputs, dtype=tf.float32)
</code></pre>
Tensor Object is not Iterable with BasicLSTMCell
<p>I have the following code: </p>

<pre><code>def dense_layers(pool3):
    with tf.variable_scope('local1') as scope:
        # Move everything into depth so we can perform a single matrix multiply.
        shape_d = pool3.get_shape()
        shape = shape_d[1] * shape_d[2] * shape_d[3]
        # tf_shape = tf.stack(shape)
        tf_shape = 1024

        print("shape:", shape, shape_d[1], shape_d[2], shape_d[3])

        # So note that tf_shape = 1024, this means that we have 1024 features are fed into the network. And
        # the batch size = 1024. Therefore, the aim is to divide the batch_size into num_steps so that
        reshape = tf.reshape(pool3, [-1, tf_shape])
        # Now we need to reshape/divide the batch_size into num_steps so that we would be feeding a sequence
        # And note that most importantly is to have batch_partition_length followed by step_size in the parameter list.
        lstm_inputs = tf.reshape(reshape, [batch_partition_length, step_size, tf_shape])

        # print('RNN inputs shape: ', lstm_inputs.get_shape()) # -&gt; (128, 8, 1024).

        # Note that the state_size is the number of neurons.
        lstm = tf.contrib.rnn.BasicLSTMCell(state_size)
        lstm_outputs, final_state = tf.nn.dynamic_rnn(cell=lstm, inputs=lstm_inputs, initial_state=init_state)
        tf.assign(init_state, final_state)
</code></pre>

<p>So, I am taking the output of the pool layer and try to feed it into the LSTM in the network. </p>

<p>Initially I have declared the following: </p>

<pre><code>state_size = 16
step_size = 8

batch_partition_length = int(batch_size / step_size)

init_state = tf.Variable(tf.zeros([batch_partition_length, state_size]))    # -&gt; [128, 16].
</code></pre>

<p>Therefore, I am getting an error on:</p>

<pre><code>lstm_outputs, final_state = tf.nn.dynamic_rnn(cell=lstm, inputs=lstm_inputs, initial_state=init_state)
</code></pre>

<p>As follows: </p>

<pre><code>Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/AffectiveComputing/Brady_with_LSTM.py", line 197, in &lt;module&gt;
    predictions = dense_layers(conv_nets_output)
  File "C:/Users/user/PycharmProjects/AffectiveComputing/Brady_with_LSTM.py", line 162, in dense_layers
    lstm_outputs, final_state = tf.nn.dynamic_rnn(cell=lstm, inputs=lstm_inputs, initial_state=init_state)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\rnn.py", line 553, in dynamic_rnn
    dtype=dtype)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\rnn.py", line 720, in _dynamic_rnn_loop
    swap_memory=swap_memory)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2623, in while_loop
    result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2456, in BuildLoop
    pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\control_flow_ops.py", line 2406, in _BuildLoop
    body_result = body(*packed_vars_for_body)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\rnn.py", line 705, in _time_step
    (output, new_state) = call_cell()
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\ops\rnn.py", line 691, in &lt;lambda&gt;
    call_cell = lambda: cell(input_t, state)
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\contrib\rnn\python\ops\core_rnn_cell_impl.py", line 238, in __call__
    c, h = state
  File "C:\Users\user\AppData\Local\Continuum\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 504, in __iter__
    raise TypeError("'Tensor' object is not iterable.")
TypeError: 'Tensor' object is not iterable.
</code></pre>

<p>Any help is much appreciated!! </p>