C4W2 - Alpaca model

Hi, I don’t pass the tests but I can’t see where my mistake is:

Test failed
Expected value

[‘Functional’, (None, 5, 5, 1280), 2257984]

does not match the input value:

[‘GlobalAveragePooling2D’, (None, 3), 0]

My code:

# Freeze the base model by making it non trainable
base_model.trainable = False

# create the input layer (Same as the imageNetv2 input size)
inputs = tf.keras.Input(shape=input_shape) 

# apply data augmentation to the inputs
x = data_augmentation(inputs)

# data preprocessing using the same weights the model was trained on
x = tf.keras.applications.mobilenet_v2.preprocess_input(x)

# set training to False to avoid keeping track of statistics in the batch norm layer
base_model.training = False

# Add the new Binary classification layers
# use global avg pooling to summarize the info in each channel
x = tfl.GlobalAveragePooling2D()(x)
#include dropout with probability of 0.2 to avoid overfitting
x = tfl.Dropout(rate=0.2)(x)
    
# create a prediction layer with one neuron (as a classifier only needs one)
prediction_layer = tf.keras.layers.Dense(1, activation='linear')

Can someone see what is wrong ?
Thanks !

# set training to False to avoid keeping track of statistics in the batch norm layer
base_model.training = False

I guess the error is in this line of code. We still need to feed the input, i.e. x into the base_model, and store it’s output in x. According to your code, it is just setting the ‘training’ parameter to False, and not performing this input-output step.
Try to replace it with
x = base_model(x, training=False)

2 Likes

That was it ! Obviously it has to go through the model but the comment confused me I think, Thank you !

1 Like