title: Getting Invalid argument: shape of all inputs must match:values[0].shape = [401408] != values[1].shape = [24485888] when using IoU metric in keras
body: <p>I'm using UNet to train on the TACO dataset, which is in COCO format. I tried training my model with the accuracy metric, only to end up with validation accuracy and accuracy reaching 1.000, which is honestly too good to be true. I was told that accuracy isn't exactly a fitting metric for segmentation problems, which is why I tried using IoU. Unfortunately, I get the following errors:</p>
  
  <pre><code>InvalidArgumentError: 2 root error(s) found.
    (0) Invalid argument:  Shapes of all inputs must match: values[0].shape = [401408] != values[1].shape = [24485888]
       [[node confusion_matrix/stack_1 (defined at &lt;ipython-input-7-4238ab807505&gt;:96) ]]
    (1) Invalid argument:  Shapes of all inputs must match: values[0].shape = [401408] != values[1].shape = [24485888]
       [[node confusion_matrix/stack_1 (defined at &lt;ipython-input-7-4238ab807505&gt;:96) ]]
       [[confusion_matrix/stack_1/_96]]
  </code></pre>
  
  <p>I don't know what I'm doing wrong, since my images are being resized as they are passed into my data generator function by this function:</p>
  
  <pre><code>def getImage(imageObj, img_folder, input_image_size):
      # Read and normalize an image
      train_img = io.imread(img_folder + '/' + imageObj['file_name'])/255.0
      # Resize
      train_img = cv2.resize(train_img, input_image_size)
      if (len(train_img.shape)==3 and train_img.shape[2]==3): # If it is a RGB 3 channel image
          return train_img
      else: # To handle a black and white image, increase dimensions to 3
          stacked_img = np.stack((train_img,)*3, axis=-1)
          return stacked_img
  </code></pre>
  
  <p>where input_image_size = (224,224). In my UNet model, the input layer is as follows:</p>
  
  <pre><code>##Input Layer
  inputs = Input((IMG_WIDTH, IMG_HEIGHT, IMG_CHANNELS))
  </code></pre>
  
  <p>where IMG_WIDTH and IMG_HEIGHT are both 224, and IMG_CHANNELS = 3. I'm also using sparse_categorical_crossentropy for my loss function. I'm pretty new to this, and I don't know what I'm doing wrong. Any help would be much appreciated.
  Cheers!</p>