title: Flattening two last dimensions of a tensor in TensorFlow
body: <p>I'm trying to reshape a tensor from <code>[A, B, C, D]</code> into <code>[A, B, C * D]</code> and feed it into a <code>dynamic_rnn</code>. Assume that I don't know the B, C, and D in advance (they're a result of a convolutional network).</p>
  
  <p>I think in Theano such reshaping would look like this:</p>
  
  <pre><code>x = x.flatten(ndim=3)
  </code></pre>
  
  <p>It seems that in TensorFlow there's no easy way to do this and so far here's what I came up with:</p>
  
  <pre><code>x_shape = tf.shape(x)
  x = tf.reshape(x, [batch_size, x_shape[1], tf.reduce_prod(x_shape[2:])]
  </code></pre>
  
  <p>Even when the shape of <code>x</code> is known during graph building (i.e. <code>print(x.get_shape())</code> prints out absolute values, like <code>[10, 20, 30, 40]</code> after the reshaping <code>get_shape()</code> becomes <code>[10, None, None]</code>. Again, still assume the initial shape isn't known so I can't operate with absolute values.</p>
  
  <p>And when I'm passing <code>x</code> to a <code>dynamic_rnn</code> it fails:</p>
  
  <pre><code>ValueError: Input size (depth of inputs) must be accessible via shape inference, but saw value None.
  </code></pre>
  
  <p>Why is <code>reshape</code> unable to handle this case? What is the right way of replicating Theano's <code>flatten(ndim=n)</code> in TensorFlow with tensors of rank 4 and more?</p>