Search code examples
tensorflowresnetpre-trained-model

Error while loading a pretrained resnet model


I am trying to load the pre-trained ResNet model in the below link https://drive.google.com/open?id=1xkVK92XLZOgYlpaRpG_-WP0Elzg4ewpw

But it gives RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

What could be the possible issue?

import tensorflow as tf
import tensorflow.contrib.slim as slim

# Let's load a previously saved meta graph in the default graph
# This function returns a Saver
saver = tf.train.import_meta_graph('model.ckpt-0.meta')

# We can now access the default graph where all our metadata has been loaded
graph = tf.get_default_graph()

with tf.Session(graph=tf.Graph()) as sess:

    saver.restore(sess, 'model.ckpt-0.data-00000-of-00001')
    print('Worked')

Solution

  • with tf.Session() as sess:
    #  tf.saved_model.loader.load(sess, [tag_constants.TRAINING], export_dir)
    
      saver = tf.train.import_meta_graph('C://Users//hardi//tutorial//resnet//model.ckpt.meta')
    #  new_saver   = saver.restore(sess, tf.train.latest_checkpoint('C://Users//hardi//tutorial//resnet//'))
      saver.restore(sess, 'model.ckpt')
      graph = tf.get_default_graph()
      print('success')
    

    The error was to bring the saver instance in the loop and use 'model.ckpt' instead of 'model.ckpt-0.data-00000-of-00001' as V2 checkpoint found solution here https://github.com/tensorflow/models/issues/2676