Add the new Binary classification layers in programming assignment: Transfer Learning with MobileNet

Hey there,
In DLS course 4, week-2, in programming assignment: transfer learning with MobileNet, when I tried to add Add the new Binary classification layers, the following error raised. Could someone correct me over this? Thanks
# 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(0.2)(x)
# create a prediction layer with one neuron (as a classifier only needs one)
prediction_layer=tfl.Dense(units=1, activation='sigmoid')


outputs = prediction_layer(x) 
model = tf.keras.Model(inputs, outputs)

Error message:
AttributeError Traceback (most recent call last)
10 [‘Dense’, (None, 1), 1281, ‘linear’]] #linear is the default activation
—> 12 comparator(summary(model2), alpaca_summary)
14 for layer in summary(model2):

~/work/W2A2/ in summary(model)
29 result =
30 for layer in model.layers:
—> 31 descriptors = [, layer.output_shape, layer.count_params()]
32 if (type(layer) == Conv2D):
33 descriptors.append(layer.padding)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ in output_shape(self)
285 RuntimeError: if called in Eager mode.
286 “”"
→ 287 return nest.map_structure(backend.int_shape, self.output)
289 def _set_output_names(self):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ in output(self)
268 RuntimeError: if called in Eager mode.
269 “”"
→ 270 return self._nested_outputs
272 @property

AttributeError: ‘Sequential’ object has no attribute ‘_nested_outputs’


The test expects you to use the default activation (which is ‘linear’) rather than ‘sigmoid’ in the prediction layer.

Hai. I just wonder why we use linear activation function. Can you explain @reinoudbosch ?

Hi kelvinn,

That question was answered here.