[week 3] Image Segmentation with U-Net

I’ve got the following error in the unet_model:

Expected value
[‘Conv2D’, (None, 6, 8, 512), 1180160, ‘same’, ‘relu’, ‘HeNormal’]

does not match the input value:
[‘Conv2D’, (None, 6, 8, 256), 590080, ‘same’, ‘relu’, ‘HeNormal’]

I don’t understand where is the problem. I am using:
cblock2 = conv_block(cblock1[0], n_filters2)
cblock3 = conv_block(cblock2[0], n_filters
4)
cblock4 = conv_block(cblock3[0], n_filters*8, dropout_prob=0.3)

and
ublock7 = upsampling_block(ublock6, cblock3[1], n_filters/2)
ublock8 = upsampling_block(ublock7, cblock2[1], n_filters/4)
ublock9 = upsampling_block(ublock8, cblock1[1], n_filters/8)

Hi cmaroblesg,

For the ublocks, at each step, you should use half the number of filters of the previous block. The previous block before ublock6 is cblock5. So ublock6 should have half the number of filters of cblock5. Then ublock7 should have half the number of filters of ublock6 and so on.

Hope this helps.

1 Like

thank you very much, I’ve found the issues and I’ve corrected it. Also, I have to modify the cblocks.

def unet_model(input_size=(96,128,3), n_filters=32, n_classes=23):
“”"
Unet model

Arguments:
    input_size -- Input shape 
    n_filters -- Number of filters for the convolutional layers
    n_classes -- Number of output classes
Returns: 
    model -- tf.keras.Model
"""
inputs = Input(input_size)
# Contracting Path (encoding)
# Add a conv_block with the inputs of the unet_ model and n_filters
### START CODE HERE
cblock1 = conv_block(inputs,   n_filters= n_filters)
cblock2 = conv_block(cblock1[0],n_filters=n_filters*2)
cblock3 = conv_block(cblock2[0],n_filters=n_filters*4)
cblock4 = conv_block(cblock3[0],n_filters=n_filters*8,dropout_prob=0.3)
cblock5 = conv_block(cblock4[0],n_filters=n_filters*16,dropout_prob=0.3,max_pooling=False)

YOUR CODE ENDS HERE

Expanding Path (decoding)

Add the first upsampling_block.

Use the cblock5[0] as expansive_input and cblock4[1] as contractive_input and n_filters * 8

ublock6 = upsampling_block(None, None, None)

Chain the output of the previous block as expansive_input and the corresponding contractive block output.

Note that you must use the second element of the contractive block i.e before the maxpooling layer.

At each step, use half the number of filters of the previous block

ublock7 = upsampling_block(None, None, None)

ublock8 = upsampling_block(None, None, None)

ublock9 = upsampling_block(None, None, None)

YOUR CODE STARTS HERE

ublock6 = upsampling_block(cblock5[0], cblock4[1],  n_filters*8)
ublock7 = upsampling_block(ublock6, cblock3[1],  n_filters*4)
ublock8 = upsampling_block(ublock7, cblock2[1],  n_filters*2)
ublock9 = upsampling_block(ublock8, cblock1[1],  n_filters*1)

YOUR CODE ENDS HERE*

conv9 = Conv2D(n_filters,
         kernel_size =3,
         activation='relu',
               padding='same',kernel_initializer='he_normal')(ublock6)

Add a Conv2D layer with n_classes filter, kernel size of 1 and a ‘same’ padding

conv10 = Conv2D(None, None, padding=None)(conv9)

YOUR CODE STARTS HERE

conv10 = Conv2D(n_classes ,kernel_size=1)(conv9)

YOUR CODE ENDS HERE

model = tf.keras.Model(inputs=inputs, outputs=conv10)

return model

error is …


could you please help me with this

1 Like

I have the same error. DId you resolve this?

You gave wrong input parameters to Conv2D relu should be ReLU and HeNormal should be he_normal also no of filter is incorrect