title: Why do you have to reshape inputs in Keras/Tensorflow 2?
body: <p>I have a simple network:</p>
  
  <pre><code>input_layer = Input(1)
  inner_layer = Dense(4, activation='relu')(input_layer)
  output_layer = Dense(1, activation='linear')(inner_layer)
  model = Model(input_layer, output_layer)
  optimizer = Adam(learning_rate=0.01)
  model.compile(optimizer=optimizer, loss='mse')
  </code></pre>
  
  <p>Intuitively, inference for input <code>0</code> would simply be <code>model.predict(0)</code>. However this generates this error: <code>expected input_2 to have 2 dimensions, but got array with shape ()</code></p>
  
  <p>I understand it expects the input (which is a single number) to be two dimensional, but I don't understand what Tensorflow accepts as valid input. I tried many different combinations of inputs, some work and some don't, it seems quite inconsistent and the warnings/error are usually not useful:</p>
  
  <h2>When calling <code>model.predict()</code>:</h2>
  
  <ul>
  <li><code>model.predict(0)</code> - Throws</li>
  <li><code>model.predict([0])</code> - <strong>Works</strong></li>
  <li><code>model.predict([[0]])</code> - <strong>Works</strong></li>
  </ul>
  
  <h2>When calling <code>model()</code> (I saw <a href="https://stackoverflow.com/a/58474218/6104191">here</a> that's needed to get the gradients):</h2>
  
  <ul>
  <li><code>model(0)</code> - Throws</li>
  <li><code>model([0])</code> - Throws</li>
  <li><code>model([[0]])</code> - Throws</li>
  </ul>
  
  <h2>When using <code>np.reshape</code>:</h2>
  
  <ul>
  <li><code>model(np.reshape(0,[1,1]))</code> - <strong>Works</strong></li>
  <li><code>model(np.reshape([0],[1,1]))</code> - <strong>Works</strong></li>
  <li><code>model(np.reshape([[0]],[1,1]))</code> - <strong>Works</strong></li>
  </ul>
  
  <p>What seems to be working consistently is using numpy's <code>reshape</code> function. it always works both for <code>model.predict()</code> and for <code>model()</code> on all the inputs as long as they're reshaped to a <code>[1,1]</code> shape.</p>
  
  <h2>My questions:</h2>
  
  <ol>
  <li>What are the guidelines to feeding inputs into tensorflow models in regards to inputs shapes/types?</li>
  <li>What does "<code>shape ()</code>" mean?</li>
  <li>What does "<code>(None, 1)</code>" mean?</li>
  <li>Why does <code>reshape</code> work but <code>[[0]]</code> does not? Both create a 2-dimensional collection.</li>
  <li>Why when calling <code>model(0)</code>/<code>model([0])</code>/<code>model([[0]])</code> does this warning show: <code>WARNING:tensorflow:Model was constructed with shape Tensor("input_1:0", shape=(None, 1), dtype=float32) for input (None, 1), but it was re-called on a Tensor with incompatible shape ()</code>? </li>
  </ol>