Skip to Content
Mastering Computer Vision with TensorFlow 2.x
book

Mastering Computer Vision with TensorFlow 2.x

by Krishnendu Kar
May 2020
Beginner to intermediate
430 pages
10h 39m
English
Packt Publishing
Content preview from Mastering Computer Vision with TensorFlow 2.x

Constructing the final model using transfer learning

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) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Computer Vision with TensorFlow 2

Hands-On Computer Vision with TensorFlow 2

Benjamin Planche, Eliot Andres

Publisher Resources

ISBN: 9781838827069Supplemental Content