May 2020
Beginner to intermediate
430 pages
10h 39m
English
We start by defining a function called build_final_model(), which takes in the base model and model parameters such as dropout, fully connected layers, and the number of classes. We first freeze the base model by using layer.trainable = False. We then flatten the base model output feature vector for subsequent processing. Next, we add a fully connected layer and dropout to the flattened feature vector to predict the new class using the softmax layer:
def build_final_model(base_model, dropout, fc_layers, num_classes): for layer in base_model.layers: layer.trainable = False x = base_model.output x = Flatten()(x) for fc in fc_layers: # New FC layer, random init x = Dense(fc, activation='relu')(x) ...