title: Temporarily merge the batch dimension in Keras
body: <p>I have a Keras model that has in input shape of <code>[None, 500, 500, 3]</code> and output shape of <code>[None, 1]</code>. Now, I want to make a wrapper model that has an input shape of <code>[None, 48, 500, 500, 3]</code>, and output shape of <code>[None, 48]</code>.</p>
  <p>To do that, the naive way is to iterate 48 times on the second axis and apply the first model, then use Keras' <code>Concatenate</code> layer to get the desired shape.</p>
  <pre class="lang-py prettyprint-override"><code>model_outputs = []
  for i in range(inputs.shape[1]):
      im_block = inputs[:, i]
      model_outputs += [self.model(im_block)]
  return Concatenate()(model_outputs)
  </code></pre>
  <p>However, this makes the graph quite complicated. So I would like to do the following instead:</p>
  <pre><code>        [None, 48, 500, 500, 3]
       -&gt; [None*48,  500, 500, 3]
             (apply the model)
       -&gt; [None*48,  1]
       -&gt; [None, 48, 1]
  </code></pre>
  <p>My attempt at that is</p>
  <pre class="lang-py prettyprint-override"><code>outputs = tf.reshape(inputs, (inputs[0] * inputs[1], *inputs[2:]))
  outputs = self.model(outputs)
  outputs = tf.reshape(outputs, (inputs[0], inputs[1]))
  return outputs
  </code></pre>
  <p>But this gives me</p>
  <pre><code>TypeError: Cannot iterate over a tensor with unknown first dimension.
  </code></pre>
  <p>Is there a way to do that ?</p>