Chester Cheng
Chester Cheng

Reputation: 158

file doesn't exist after saving with tensorflow

I saved my model using tf.train.Saver('./model.ckpt'), when I went to the local directory, I have found files named model.ckpt.index, model.ckpt.meta and model.ckpt.data-00000-of-00001, but not model.ckpt. As a consequence, I wasn't able to restore the model. Anyone know if i did anything wrong? Here's my code

class autoencoder(object):
    def __init__(self, network_architecture, learning_rate=0.001, regularization_constant=1):
        self.network_arch = network_architecture
        self.X = tf.placeholder(tf.float32, [None, network_architecture['n_input']])
        self.c = tf.Variable(regularization_constant, dtype=tf.float32)

        self._initialize_weights()
        self._build_graph()

        self.cost, self.optimizer = self._cost_optimizer(learning_rate)

        init = tf.global_variables_initializer()
        self.saver = tf.train.Saver()

        self.sess = tf.Session()
        self.sess.run(init)

   ...

    def save(self, path):
        self.saver.save(self.sess, path)

    def load(self, path):
        self.saver.restore(self.sess, path)

Upvotes: 0

Views: 1244

Answers (1)

MatthewScarpino
MatthewScarpino

Reputation: 5936

The *.meta file contains your MetaGraph, and you can import it with:

saver = tf.train.import_meta_graph("model.ckpt.meta")

Then you can restore the graph's variables.

saver.restore(sess, "model.ckpt")

You can save additional model data to the metagraph by calling tf.train.export_meta_graph.

Alternatively, you can store your application's model using a SavedModel, which can contain multiple MetaGraphs. The documentation is here.

Upvotes: 2

Related Questions