title: Why am I getting a Value error on my python code
body: <p>Used: tensorflow, keras, python, flask</p>
  <pre><code>Error: ValueError: Input 0 of layer conv2d_3 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (32, 224, 1)
  </code></pre>
  <p>Structure of Neural Network:</p>
  <pre><code>_________________________________________________________________
  Layer (type)                 Output Shape              Param #   
  =================================================================
  rescaling_1 (Rescaling)      (None, 224, 224, 3)       0         
  _________________________________________________________________
  conv2d (Conv2D)              (None, 224, 224, 16)      448       
  _________________________________________________________________
  max_pooling2d (MaxPooling2D) (None, 112, 112, 16)      0         
  _________________________________________________________________
  conv2d_1 (Conv2D)            (None, 112, 112, 32)      4640      
  _________________________________________________________________
  max_pooling2d_1 (MaxPooling2 (None, 56, 56, 32)        0         
  _________________________________________________________________
  conv2d_2 (Conv2D)            (None, 56, 56, 64)        18496     
  _________________________________________________________________
  max_pooling2d_2 (MaxPooling2 (None, 28, 28, 64)        0         
  _________________________________________________________________
  flatten (Flatten)            (None, 50176)             0         
  _________________________________________________________________
  dense (Dense)                (None, 128)               6422656   
  _________________________________________________________________
  dense_1 (Dense)              (None, 2)                 258       
  =================================================================
  Total params: 6,446,498
  Trainable params: 6,446,498
  Non-trainable params: 0
  _________________________________________________________________
  
  from flask import *
  import h5py
  from PIL import Image, ImageFile
  from io import BytesIO
  from werkzeug.utils import secure_filename
  import numpy as np
  from matplotlib import image
  import os
  import uuid
  from tensorflow.keras.models import load_model
  from tensorflow.keras.preprocessing import image
  from werkzeug.wrappers import Request, Response
  import tensorflow as tf
  import numpy as np
  IMGSIZE=224
  IMGCHANNELS=3*224*224
  ALLOWEDEXTENSIONS=['png','jpg','txt','pdf','jfif','jpeg','gif']
  classes=('NORMAL','PNEMONIAL')
  app=Flask(__name__)
  model=load_model(os.path.join(os.getcwd(),&quot;chestXray.h5&quot;))
  def preprocess(inputs):
      inputs=np.array(inputs)
      l=inputs.size
      for i in range(l):
          j=inputs[i]
          j /=255
          inputs[i]=j
          j=0
      return inputs
  #Allowed file function
  def allowededFile(filename):
      return '.' in filename and filename.rsplit('.',1)[1] in ALLOWEDEXTENSIONS
  #Flask ROutes
  @app.route(&quot;/&quot;)
  def index():
      return render_template(&quot;chest.html&quot;, Prediction=&quot; &quot;)
  @app.route(&quot;/api/image&quot;, methods=['GET','POST'])
  def api():    
      file=request.files['file']
      if file.filename=='':
          return render_template(&quot;chest.html&quot;, Prediction=&quot;You did not upload a file&quot;)
      if file and allowededFile(file.filename):
          filename=secure_filename(file.filename)
          print(&quot;***&quot;+filename)
          x=[]
          
          ImageFile.LOAD_TRUNCATED_IMAGES=False
          img=Image.open(BytesIO(file.read()))
          img.load()
          img=img.resize((IMGSIZE,IMGSIZE),Image.ANTIALIAS)
          x=image.img_to_array(img)
          
          #np.expand_dims(x,axis=-1)
          x.reshape((1,224,224,1))     
          pred=model.predict(x)
          lst=decode_predictions(pred,top=3)
          items=[]
          for item in lst[0]:
              items.append({'name':item[1],'probability':float(item[2])})
          response={'prediction':items}
          return render_template(&quot;chest.html&quot;,Prediction=&quot;The state of this person's lungs is most likely {}&quot;.format(response))       
      else:
          return render_template(&quot;chest.html&quot;,Prediction='Invalid file extension')
      
  if __name__==&quot;__main__&quot;:
      from werkzeug.serving import run_simple
      run_simple('localhost',9000,app)
  </code></pre>
  <p>Model Code:</p>
  <pre><code>model=Sequential([
      layers.experimental.preprocessing.Rescaling(1./255,input_shape=(imgSize,imgSize,3)),
      layers.Conv2D(16,3,padding='same',activation='relu'),
      layers.MaxPooling2D(),
      layers.Conv2D(32,3,padding='same',activation='relu'),
      layers.MaxPooling2D(),
      layers.Conv2D(64,3,padding='same',activation='relu'),
      layers.MaxPooling2D(),
      layers.Flatten(),
      layers.Dense(128, activation='relu'),
      layers.Dense(numClasses)
      ])
      
  
   
  </code></pre>