5

https://github.com/tensorflow/models/tree/master/slim

This gives download link for checkpoints for Inception v1-4 pretrained models. However, the tar.gz contains only the .ckpt file.

In the tutorial on using Inception v3 2012 [This link], the tar.gz contains .pb and .pbtxt files which are used for classification.

How can i use just the .ckpt file to generate respective .pb and .pbtxt files? OR Is there any alternate way of using the .ckpt file for classification?

megan adams
  • 355
  • 1
  • 6
  • 10

1 Answers1

0

Even i am also trying inception_v4 model. During my search i could able to find the the checkpoint files contains the weights. So inorder to use this, inception_v4 graph needed to be loaded from inception_v4.py and the session needed to be restored from the checkpoint file. Following code will read the checkpoint file and create the protobuf file.

import tensorflow as tf
slim = tf.contrib.slim
import tf_slim.models.slim.nets as net
# inception_v3_arg_scope
import tf_slim
import inception_v4 as net
import cv2


# checkpoint file
checkpoint_file = '/home/.../inception_v4.ckpt' 

# Load Session
sess = tf.Session()
arg_scope = net.inception_v4_arg_scope()
input_tensor = tf.placeholder(tf.float32, [None, 299, 299, 3])
with slim.arg_scope(arg_scope):
    logits, end_points = net.inception_v4(inputs=input_tensor)

saver = tf.train.Saver()
saver.restore(sess, checkpoint_file)
f = tf.gfile.FastGFile('./mynet.pb', "w")
f.write(sess.graph_def.SerializeToString())
f.close()

# reading the graph
#
with tf.gfile.FastGFile('./mynet.pb', 'rb') as fp:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(fp.read())

    with tf.Session(graph=tf.import_graph_def(graph_def, name='')) as sess:
    # op = sess.graph.get_operations()
    # with open('./tensors.txt', mode='w') as fp:
    #     for m in op:
    #     #     print m.values()
    #         fp.write('%s \n' % str(m.values()))
    cell_patch = cv2.imread('./car.jpg')
    softmax_tensor = sess.graph.get_tensor_by_name('InceptionV4/Logits/Predictions:0')
    predictions = sess.run(softmax_tensor, {'Placeholder:0': cell_patch})

But the above code wont give you the predictions. Because I am facing problem in giving the input to the graph. But It can be of good starting point to work with checkpoint files.

Checkpoint is downloaded from following link checkpoints