RyanKor / 2021-google-ml-bootcamp

Google Machine Learning Bootcamp 2021
13 stars 0 forks source link

[Assignment Error] Error in Test in Assignment 2, Week1, Course4 #13

Closed RyanKor closed 3 years ago

RyanKor commented 3 years ago
# GRADED FUNCTION: convolutional_model

def convolutional_model(input_shape):
    """
    Implements the forward propagation for the model:
    CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> DENSE

    Note that for simplicity and grading purposes, you'll hard-code some values
    such as the stride and kernel (filter) sizes. 
    Normally, functions should take these values as function parameters.

    Arguments:
    input_img -- input dataset, of shape (input_shape)

    Returns:
    model -- TF Keras model (object containing the information for the entire training process) 
    """

    input_img = tf.keras.Input(shape=input_shape)
    ## CONV2D: 8 filters 4x4, stride of 1, padding 'SAME'
    Z1 = tf.keras.layers.Conv2D(8, (4, 4), strides=(1, 1), padding="same", activation="relu")(input_img)

    ## RELU
    # A1 = tf.keras.layers.ReLU()

    ## MAXPOOL: window 8x8, stride 8, padding 'SAME'
    P1 = tf.keras.layers.MaxPool2D(pool_size=(8, 8),strides=(8,8), padding='same')(Z1)

    ## CONV2D: 16 filters 2x2, stride 1, padding 'SAME'
    Z2 = tf.keras.layers.Conv2D(16, (2, 2), strides=(1, 1), padding="same",activation="relu")(P1)

    ## RELU
    # A2 = tf.keras.layers.ReLU()

    ## MAXPOOL: window 4x4, stride 4, padding 'SAME'
    P2 = tf.keras.layers.MaxPool2D(pool_size=(4, 4),strides=(4,4), padding='same')(Z2)

    ## FLATTEN
    F = tf.keras.layers.Flatten()(P2)

    ## Dense layer
    ## 6 neurons in output layer. Hint: one of the arguments should be "activation='softmax'" 
    outputs = tf.keras.layers.Dense(6, activation='softmax')(F)

    # YOUR CODE STARTS HERE

    # YOUR CODE ENDS HERE
    model = tf.keras.Model(inputs=input_img, outputs=outputs)
    return model

Error 내용

Test failed 
 Expected value 

 ['Conv2D', (None, 64, 64, 8), 392, 'same', 'linear', 'GlorotUniform'] 

 does not match the input value: 

 ['Conv2D', (None, 64, 64, 8), 392, 'same', 'relu', 'GlorotUniform']

에러 설명

아마 해당 에러는 Conv2D 함수에 직접적으로 Relu 함수를 넣어 실행한 것이 에러를 초래한 것으로 보인다.

별도로 빼서 넣는 방법이 떠오르지 않아서 일단 이렇게 진행했는데, 해당 에러를 고칠 필요가 있다.

RyanKor commented 3 years ago

Error Solved!

Explanation :

# GRADED FUNCTION: convolutional_model

def convolutional_model(input_shape):
    """
    Implements the forward propagation for the model:
    CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> DENSE

    Note that for simplicity and grading purposes, you'll hard-code some values
    such as the stride and kernel (filter) sizes. 
    Normally, functions should take these values as function parameters.

    Arguments:
    input_img -- input dataset, of shape (input_shape)

    Returns:
    model -- TF Keras model (object containing the information for the entire training process) 
    """

    input_img = tf.keras.Input(shape=input_shape)
    ## CONV2D: 8 filters 4x4, stride of 1, padding 'SAME'
    Z1 = tf.keras.layers.Conv2D(8, (4, 4), strides=(1, 1), padding="same")(input_img)

    ## RELU
    A1 = tf.keras.layers.ReLU()(Z1) # answer code

    ## MAXPOOL: window 8x8, stride 8, padding 'SAME'
    P1 = tf.keras.layers.MaxPool2D(pool_size=(8, 8),strides=(8,8), padding='same')(A1)

    ## CONV2D: 16 filters 2x2, stride 1, padding 'SAME'
    Z2 = tf.keras.layers.Conv2D(16, (2, 2), strides=(1, 1), padding="same")(P1)

    ## RELU
    A2 = tf.keras.layers.ReLU()(Z2) # answer code

    ## MAXPOOL: window 4x4, stride 4, padding 'SAME'
    P2 = tf.keras.layers.MaxPool2D(pool_size=(4, 4),strides=(4,4), padding='same')(A2)

    ## FLATTEN
    F = tf.keras.layers.Flatten()(P2)

    ## Dense layer
    ## 6 neurons in output layer. Hint: one of the arguments should be "activation='softmax'" 
    outputs = tf.keras.layers.Dense(units=6, activation='softmax')(F)

    model = tf.keras.Model(inputs=input_img, outputs=outputs)
    return model