This question regards the Semantic Segmentation example Assignment 2 of Wk3 in Course 4.
I wrote a nearly identical segmenter module (“unet”), but for a binary task on biomedical images. The model trains well, but the prediction masks (rank 4) produced by the model (mine as well as Coursera’s) have what to me is an extra dimension.
Furthermore, the last axis (axis 3) of the predicted masks, of shape 2, contains two arrays/images, shown below, which seem identical. The duplication seems redundant and is the cause of a Keras error (the module can’t compute binary crossentropy as metric --because “true mask” and “predicted mask” are of different shapes).
Here is the code that generates the mask:
pred = unet.predict(sample_image[tf.newaxis, …])
pred.shape
(1, 1024, 1024, 2)
pred = (tf.squeeze(pred,[0]))
pred.shape
(1024,1024,2)
pred0= tf.expand_dims(pred[:, :, 0],-1) #slicing the tensor and expanding for display
pred1= tf.expand_dims(pred[:, :, 1],-1)
display([pred0, pred1])
surprisingly, the two slices are identical.
WHY does model.predict do this? And, could the duplication be avoided?
