title: WARNING:tensorflow:Model was constructed with shape (4, 112, 112, 3) for input ..., but it was called on an input with incompatible shape ((None, 112)
body: <p>I trained a model and saved it as a h5 file. When I reuse the model and try to make a prediction using an image, it throws an error saying that it is incompatible.</p>
  <p>How can I eliminate the warning?</p>
  <p>Here is the code:</p>
  <pre><code>CATEGORIES = [&quot;Tuberculosis&quot;, &quot;Normal&quot;]
  
  def prepare(filepath):
    IMG_SIZE = 112
    img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE)
    new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
    return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
  
  model = tf.keras.models.load_model(&quot;tuberculosis.h5&quot;)
  
  prediction = model.predict([prepare(&quot;test.jpg&quot;)])
  print(CATEGORIES[int(prediction[0][0])])
  </code></pre>
  <p>Here is the error it throws:</p>
  <pre><code>WARNING:tensorflow:Model was constructed with shape (4, 112, 112, 3) for input KerasTensor(type_spec=TensorSpec(shape=(4, 112, 112, 3), dtype=tf.float32, name='conv2d_input'), name='conv2d_input', description=&quot;created by layer 'conv2d_input'&quot;), but it was called on an input with incompatible shape (None, 112).
  
  
  ValueError                                
  Traceback (most 
  recent call last)
  &lt;ipython-input-79-6d3f8245e17a&gt; in &lt;module&gt;()
  ----&gt; 1 prediction = model.predict([prepare(&quot;test.jpg&quot;)])
        2 print(CATEGORIES[int(prediction[0][0])])
  
  1 frames
  /usr/local/lib/python3.7/dist- 
  packages/tensorflow/python/framework/func_graph.py in 
  autograph_handler(*args, **kwargs)
  1145           except Exception as e:  # pylint:disable=broad- 
  except
  1146             if hasattr(e, &quot;ag_error_metadata&quot;):
  -&gt; 1147               raise e.ag_error_metadata.to_exception(e)
  1148             else:
  1149                  raise
  
  ValueError: in user code:
  
  File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1801, in predict_function  *
      return step_function(self, iterator)
  File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1790, in step_function  **
      outputs = model.distribute_strategy.run(run_step, args=(data,))
  File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1783, in run_step  **
      outputs = model.predict_step(data)
  File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/training.py&quot;, line 1751, in predict_step
      return self(x, training=False)
  File &quot;/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py&quot;, line 67, in error_handler
      raise e.with_traceback(filtered_tb) from None
  File &quot;/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py&quot;, line 228, in assert_input_compatibility
      raise ValueError(f'Input {input_index} of layer &quot;{layer_name}&quot; '
  
  ValueError: Exception encountered when calling layer &quot;sequential&quot; (type Sequential).
  
  Input 0 of layer &quot;conv2d&quot; is incompatible with the layer: expected min_ndim=4, found ndim=2. Full shape received: (None, 112)
  
  Call arguments received:
    • inputs=('tf.Tensor(shape=(None, 112), dtype=uint8)',)
    • training=False
    • mask=None
  </code></pre>