C4 - Week 2 - Transfer_learning

I am on exercise 2. After setting training to false, how do we “Add the new binary classification layers” ?

set training to False to avoid keeping track of statistics in the batch norm layer

x = base_model(image_batch, training=False)

Add the new Binary classification layers

x.add(tfl.Dense(units=1, activation=‘sigmoid’))

use global avg pooling to summarize the info in each channel

y = GlobalAveragePooling2D()(x)

Error message:
—> 35 x.add(tfl.Dense(units=1, activation=‘sigmoid’))
37 # use global avg pooling to summarize the info in each channel

AttributeError: ‘tensorflow.python.framework.ops.EagerTensor’ object has no attribute ‘add’

If x is initialized to the base_model, how come it lacks a member function add new binary classification layers? Any tips? I am also unsure on how to proceed with integrating the global avg pooling into the model.

Hi GenTso,

The comment ‘# Add the new Binary classification layers’ refers to the global avg pooling layer, the dropout layer and the prediction layer. There is no separate ‘Binary classification layer’.

Look also at how the model is being built up. First, the input layer is created which produces the tensor inputs. Then data augmentation is applied to the tensor inputs which produces tensor ‘x’. Then preprocessing is applied to tensor x which produces the new tensor x. Then the base_model is applied to … etc.

Good luck!