Transfer network architecture

We will be replacing the final two layers with fully connected layers that are more appropriate for our use case. Since our problem is binary classification, we will replace the output layer with a single neuron with sigmoid activation, as shown in the following code:

# add a global spatial average pooling layerx = base_model.outputx = GlobalAveragePooling2D()(x)# let's add a fully-connected layerx = Dense(1024, activation='relu')(x)# and a logistic layerpredictions = Dense(1, activation='sigmoid')(x)# this is the model we will trainmodel = Model(inputs=base_model.input, outputs=predictions)

Note that we are using a GlobalAveragePooling2D layer here. This layer flattens the 4D output of the previous layer into ...

Get Deep Learning Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.