in alpaca_model(image_shape, data_augmentation)
43 prediction_layer = tf.keras.layers.Dense(1, activation=‘sigmoid’)
44
—> 45 outputs = prediction_layer(x)
46 model = tf.keras.Model(inputs, outputs)
47
AttributeError: ‘Dropout’ object has no attribute ‘shape’
Here is a snippet of my code:
# data preprocessing using the same weights the model was trained on
x = tf.keras.applications.mobilenet_v2.preprocess_input
# 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 = tf.keras.layers.GlobalAveragePooling2D()
x = tf.keras.layers.Dropout(rate = 0.2)
prediction_layer = tf.keras.layers.Dense(1, activation='sigmoid')
outputs = prediction_layer(x)
model = tf.keras.Model(inputs, outputs)
I am not sure how the global average and dropout lines are working, since I am not explicitly telling Python to use x (the previous layer) as an input.
I believe the error has to do with the GlobalAveragePooling2D and the Dropout lines, but everytime I try to put an input in either of those 2 layers, I get an error on that respective line. In the way it is now, I get an error on the “outputs” line.
You need to pass in a parameter/input for the GlobalAveragePooling2D as such:
x = tf.keras.layers.GlobalAveragePooling2D()(x) . FYI, Same error for the Dropout layer.
in alpaca_model(image_shape, data_augmentation)
36 # Add the new Binary classification layers
37 # use global avg pooling to summarize the info in each channel
—> 38 x = tf.keras.layers.GlobalAveragePooling2D()(x)
39 x = tf.keras.layers.Dropout(rate = 0.2)(x)
40
AttributeError: ‘function’ object has no attribute ‘shape’
Also, I changed the activation to ‘linear’.
Could the issue be how I am setting ‘training’ in the base_model to False?
AssertionError Traceback (most recent call last)
in
10 [‘Dense’, (None, 1), 1281, ‘linear’]] #linear is the default activation
11
—> 12 comparator(summary(model2), alpaca_summary)
13
14 for layer in summary(model2):
~/work/release/W2A2/test_utils.py in comparator(learner, instructor)
19 “\n\n does not match the input value: \n\n”,
20 colored(f"{a}", “red”))
—> 21 raise AssertionError(“Error in test”)
22 print(colored(“All tests passed!”, “green”))
23