0

i am try to save the training for my network in a checkpoint instead to trained each time i testing. So i don't know what is problem in my code when i run the test file, it going to train again. any body can help me plz ?

this is the train file

saver = tf.train.Saver()


with tf.Session(graph=graph) as session:

num_steps = 1001

session.run()

print('Initialized')

for step in range(num_steps):

  offset = (step * batch_size) % (train_labels.shape[0] - batch_size)     
  batch_data = train_dataset[offset:(offset + batch_size), :, :, :]

  batch_labels = train_labels[offset:(offset + batch_size), :]
  print("batch_labels",batch_labels)
  feed_dict = {tf_train_dataset : batch_data, tf_train_labels : batch_labels}

  _, l, predictions = session.run(
    [optimizer, loss, train_prediction ], feed_dict=feed_dict)

  if (step % 50 == 0):
    print('Minibatch loss at step %d: %f' % (step, l))
    print('Minibatch accuracy: %.1f%%' % accuracy(predictions, batch_labels))
    print('Validation accuracy: %.1f%%' % accuracy(valid_prediction.eval(), valid_labels))

save_path = saver.save(session, "/home/owner//tensorflow/tensorflow/models/image/mnist/new_dataset/models.ckpt")

print("Model saved in file: %s" % save_path)

and here is the test file:

from __future__ import print_function

import numpy as np

import tensorflow as tf

from six.moves import cPickle as pickle

from six.moves import range

import time

from datetime import datetime
import tensorflow as tf


saver = tf.train.Saver()
init = tf.initialize_all_variables()
with tf.Session() as session:

   saver.restore(session ,"/home/owner/tensorflow/tensorflow/models/image/mnist/new_dataset/models.ckpt")
   print("Model restored.")
   print('Test accuracy: %.1f%%' % accuracy(test_prediction.eval() , test_labels, force = False ))
mido
  • 69
  • 1
  • 9
  • any answer for that question ? – mido Jul 14 '16 at 18:54
  • Here is a related question with several answers that might help: http://stackoverflow.com/questions/33759623/tensorflow-how-to-restore-a-previously-saved-model-python – Shan Carter Jul 14 '16 at 21:08

0 Answers0