title: plt.imshow not showing any image on prediction
body: <p>I am trying to perform image segmentation on cityscapes dataset. Cityscapes dataset contains two directories (train and val). The files in both directories are pair images so I do some preprocessing.</p>
  <ol>
  <li>First, I split the image into original images and their masks.</li>
  <li>Then I normalize the images.</li>
  <li>Then I apply to_categorical to apply the number of classes that I have.</li>
  </ol>
  <p>Below you can see my full code. I just don't understand why I am not getting any prediction image.</p>
  <p>Training directory</p>
  <pre><code>path = &quot;/content/drive/MyDrive/Image Segmentation/cityscapes_data/train/&quot;
  train_images_list = []
  number = 1000
  # creating a list of the images inside train folder
  train_images = os.listdir(path)
  for images in train_images[0:number]:
    # read the images in the file
    image = io.imread(path + &quot;/&quot; + images,cv2.COLOR_RGB2GRAY)
    train_images_list.append(image)
  
  # convert list to array
  train_arr = np.array(train_images_list) 
  # split the image pair, obtaining all images 
  train_images = train_arr[:,:,0:256]
  # obtaining all the masks 
  train_masks = train_arr [:,:,256:512]
  train_images = np.expand_dims(train_images, axis=3)
  train_masks = np.expand_dims(train_masks, axis = 3)
  </code></pre>
  <p>Validation directory</p>
  <pre><code>path1 = &quot;/content/drive/MyDrive/Image Segmentation/cityscapes_data/val/&quot;
  val_images_list = []
  # creating a list of the images inside validation directory
  val_images = os.listdir(path1)
  for images1 in val_images:
    image1 = io.imread(path1 + &quot;/&quot; + images1, cv2.COLOR_RGB2GRAY)
    val_images_list.append(image1)
  
  # convert list to array 
  val_arr = np.array(val_images_list)
  val_images = val_arr[:,:,0:256]
  val_masks = val_arr [:,:,256:512]
  val_images = np.expand_dims(val_images, axis=3)
  val_masks = np.expand_dims(val_masks, axis=3)
  </code></pre>
  <p>Model</p>
  <pre><code>classes = 14
  
  from tensorflow.keras.utils import normalize, to_categorical
  
  train_masks_cat = to_categorical(train_masks, num_classes=classes)
  y_train_cat = train_masks_cat.reshape((train_masks.shape[0], 
                                         train_masks.shape[1], 
                                         train_masks.shape[2], 
                                         classes))
  
  test_masks_cat = to_categorical(val_masks, num_classes=classes)
  y_test_cat = test_masks_cat.reshape((val_masks.shape[0], 
                                         val_masks.shape[1], 
                                         val_masks.shape[2], 
                                         classes))
  
  train_images.shape = (1000, 256, 256, 1)
  
  y_train_cat.shape = (1000, 256, 256, 14)
  
  y_test_cat.shape = (500, 256, 256, 14)
  
  
  # Building Unet using encoder and decoder blocks
  from keras.models import Model
  from keras.layers import Input, Conv2D, MaxPooling2D,  concatenate, Conv2DTranspose, BatchNormalization, Dropout, Lambda
  from keras.layers import Activation, MaxPool2D, Concatenate
  num_filters =16
  
  def conv_block(input, num_filters):
    # first conv layer
    x = Conv2D(num_filters, kernel_size = (3,3), padding='same')(input)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
  
    # second conv layer
    x = Conv2D(num_filters, kernel_size= (3,3), padding='same')(x)
    x = BatchNormalization()(x)
    x = Activation('relu')(x)
  
    return x
  
  def encoder_block(input, num_filters):
    # conv block
    x = conv_block(input,num_filters)
    # maxpooling 
    p = MaxPool2D(strides = (2,2))(x)
    #p = Dropout(0.4)(p)
    return x,p
  
  def decoder_block(input, skip_features, num_filters):
    x = Conv2DTranspose(num_filters, (2,2), strides=2, padding='same')(input)
    x = Concatenate()([x, skip_features])
    x = conv_block(x, num_filters)
    return x
  
  
  
  
  def unet_architect(input_shape, classes):
  
    &quot;&quot;&quot; Input Layer &quot;&quot;&quot;
    inputs = Input(input_shape)
  
    &quot;&quot;&quot; Encoder &quot;&quot;&quot;
    s1,p1 = encoder_block(inputs, num_filters)
    s2,p2 = encoder_block(p1,num_filters *2) 
    s3,p3 = encoder_block(p2, num_filters *4) 
    s4,p4 = encoder_block(p3, num_filters * 8) 
  
    &quot;&quot;&quot; Bridge &quot;&quot;&quot;
    b1 = conv_block(p4,num_filters*16)
  
    &quot;&quot;&quot; Decoder &quot;&quot;&quot; 
    d1 = decoder_block(b1, s4, num_filters * 8)
    d2 = decoder_block(d1, s3, num_filters *4)
    d3 = decoder_block(d2, s2, num_filters *2)
    d4 = decoder_block(d3, s1, num_filters)
  
    &quot;&quot;&quot; Output Layer &quot;&quot;&quot;
    outputs = Conv2D(classes, (1,1), padding='same', activation = 'softmax')(d4)
  
    model = Model(inputs, outputs, name='U-Net')
  
    return model
  
  
  train_images.shape = (1000, 256, 256, 1)
  img_height = train_images.shape[1]
  img_width = train_images.shape[2]
  img_channels = train_images.shape[3]
  input_shape = (img_height, img_width,img_channels)`
  
  model = unet_architect(input_shape, classes)
  model.compile(optimizer = 'adam' , 
                loss = 'categorical_crossentropy',
                metrics=['categorical_accuracy'])
  model.summary()
  
  
  
  history =  model.fit(train_images, y_train_cat,
                       batch_size = 16, 
                       verbose = 1, 
                       epochs = 5,
                       validation_data = (val_images,y_test_cat))
  
  pred = model.predict(val_images)
  
  
  import random
  test_img_number = random.randint(0, len(val_images))
  test_img = val_images[test_img_number]
  ground_truth = val_masks[test_img_number]
  predicted_img = pred[test_img_number]
  
  test_img.shape = (256, 256, 1)
  ground_truth.shape = (256, 256, 1)
  Previously predicted_img was:
  predicted_img = (256,256,14)
  Now after applying argmax:
  predicted_img = np.argmax(predicted_img, -1)
  predicted_img = (256,256)
  
  plt.figure(figsize=(15,15))
  plt.subplot(131)
  plt.title('Original Image')
  plt.imshow(test_img[:,:,0])
  plt.subplot(132)
  plt.title('Masked Image')
  plt.imshow(ground_truth[:,:,0])
  plt.subplot(133)
  plt.title('Predicted Image')
  plt.imshow(predicted_img) 
  plt.show()
  WHY IS THE PREDICTION IMAGE SHOWING NOTHING IN THE IMAGE BELOW
  </code></pre>
  <p>I am still new to StackOverflow thats why I cant display the image. Please view the image from the link below
  thanks
  [2]: <a href="https://i.stack.imgur.com/armjk.png" rel="nofollow noreferrer">https://i.stack.imgur.com/armjk.png</a></p>