C4 - Week 3 - Image Segmentation with U-Net

I have an error using MaxPooling2D in the conv_block function :

# if dropout_prob > 0 add a dropout layer, with the variable dropout_prob as parameter
    if dropout_prob > 0:
         conv = tf.keras.layers.Dropout(dropout_prob)

    # if max_pooling is True add a MaxPooling2D with 2x2 pool_size
     if max_pooling:
        next_layer = tf.keras.layers.MaxPooling2D((2,2))

     else:
        next_layer = conv
    
     skip_connection = conv

     return next_layer, skip_connection

Error message :
AttributeError: ‘MaxPooling2D’ object has no attribute ‘op’

1 Like

You have to append the Dropout and MaxPooling2D layers to the model that you’ve already created, i.e., conv. It can be done like this: Dropout()(you_model)

15 Likes

Thanks ! :+1: :+1:
Keep missing this

2 Likes

could you help me please?

1624103257520

Hi! you need to use the “pool_size=()” argument for MaxPooling2D.

1 Like

And for those who wonder why this works, check the import:

from tensorflow.keras.layers import Dropout