How to do it...

  1. First, we start with loading the libraries, as follows:
import osimport globimport tensorflow as tf
  1. Because our task is slightly more complicated than outputting the predicted class, we need to define a function that extracts the values from different layers:
def extract_layers(vgg_layer3_out, vgg_layer4_out, vgg_layer7_out, n_classes):    decode_layer1_preskip0 = tf.layers.conv2d_transpose(vgg_layer7_out, 512, (2, 2), (2, 2), name='decode_layer1_preskip0')    decode_layer1_preskip1 = tf.layers.conv2d(vgg_layer4_out, 512, (1, 1), (1, 1), name='decode_layer1_preskip1')    decode_layer1_out = tf.add(decode_layer1_preskip0, decode_layer1_preskip1, name='decode_layer1_out')    decode_layer2_preskip0 = tf.layers.conv2d_transpose(decode_layer1_out, ...

Get Python Deep Learning Cookbook 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.