Closed TheKnowingEye closed 2 months ago
Hi @TheKnowingEye -
Thanks for reporting this issue. Here the error reproduces due to convolution shape mismatch during skip connections uses in UNET network. To resolve this error you can either use cropping or padding technique to get same shape. Padding is much better to use here to preserve image height and width.
Using Cropping:
###adding cropping 2D layer before concatenate with height and width adjusted
height = max(0,skips[level].shape[1]- x.shape[1])
width = max(0,skips[level].shape[2]- x.shape[2])
cropped_x= tf.keras.layers.Cropping2D(cropping=((0, height), (0, width)))(skips[level])
x = tf.keras.layers.Concatenate()([x, cropped_x])
Padding:
###adding padding 2D layer before concatenate with height and width adjusted
pad_top = (skips[level].shape[1] - x.shape[1]) // 2
pad_bottom = skips[level].shape[1] - x.shape[1] - pad_top
pad_left = (skips[level].shape[2] - x.shape[2]) // 2
pad_right = skips[level].shape[2] - x.shape[2] - pad_left
padded_x = tf.keras.layers.ZeroPadding2D(padding=((pad_top, pad_bottom), (pad_left, pad_right)))(x)
x = tf.keras.layers.Concatenate()([skips[level], padded_x])
Attached the gist for the reference as well.
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.
I am getting this error when I try to compile my U-NET model ValueError: A
Concatenate
layer requires inputs with matching shapes except for the concatenation axis. Received: input_shape=[(None, 88, 88, 128), (None, 89, 89, 128)]I was not getting this error when I had 256x256 as my input shape in the Input layer
How to reproduce