ValueError: Input 0 of layer max_pooling2d_12 is incompatible with the layer: expected ndim=4, found ndim=0. Full shape received: []

how can i solve this error ?

ValueError: Input 0 of layer max_pooling2d_12 is incompatible with the layer: expected ndim=4, found ndim=0. Full shape received: []

i have tried all values like conv , inputs , and ....

# UNQ_C1
# GRADED FUNCTION: conv_block
def conv_block(inputs=(96,128,3), n_filters=32, dropout_prob=0, max_pooling=True):
    """
    Convolutional downsampling block
    
    Arguments:
        inputs -- Input tensor
        n_filters -- Number of filters for the convolutional layers
        dropout_prob -- Dropout probability
        max_pooling -- Use MaxPooling2D to reduce the spatial dimensions of the output volume
    Returns: 
        next_layer, skip_connection --  Next layer and skip connection outputs
    """

    ### START CODE HERE
    conv = Conv2D(32, # Number of filters
                  3,   # Kernel size   
                  activation='relu',
                  padding='same',
                  kernel_initializer='he_normal')(inputs)
    conv = Conv2D(32, # Number of filters
                  3,   # Kernel size
                  activation='relu',
                  padding='same',
                  kernel_initializer='he_normal')(conv)
    ### END CODE HERE
    
    # if dropout_prob > 0 add a dropout layer, with the variable dropout_prob as parameter
    if dropout_prob > 0:
         ### START CODE HERE
        conv = dropout_prob
         ### END CODE HERE
         
        
    # if max_pooling is True add a MaxPooling2D with 2x2 pool_size
    if max_pooling:
        ### START CODE HERE
        next_layer = tf.keras.layers.MaxPooling2D(pool_size=(2,2))(conv)
        ### END CODE HERE
        
    else:
        next_layer = conv
        
    skip_connection = conv
    
    return next_layer, skip_connection

Upvotes: 0

Views: 576

Answers (1)

I think the problem is that you are assigning

conv = dropout_prob

So conv is a instance of tensorflow and dropout_prob is a number and the problem says thar you have to add a dropout layer, with the variable dropout_prob as parameter. not set it equal to the parameter.

The right line is:

conv = tf.keras.layers.Dropout(dropout_prob)(conv)

Upvotes: 1

Related Questions