Image classification using pre-trained VGG16 in TensorFlow

Now let us first try to predict the classes of our test images, without retraining. First, we clear the default graph and define a placeholder for images:

tf.reset_default_graph()x_p = tf.placeholder(shape=(None,image_height, image_width,3),                     dtype=tf.float32,name='x_p')

The shape of placeholder x_p is  (?, 224, 224, 3). Next, load the vgg16 model:

with slim.arg_scope(vgg.vgg_arg_scope()):     logits,_ = vgg.vgg_16(x_p,num_classes=inet.n_classes,                            is_training=False)

Add the softmax layer for producing probabilities over the classes:

probabilities = tf.nn.softmax(logits)

Define the initialization function to restore the variables, such as weights and biases from the checkpoint file.

init ...

Get Mastering TensorFlow 1.x now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.