how to restore a saved variable in tensorflow?

1,038 views
Skip to first unread message

emrec...@gmail.com

unread,
Nov 25, 2016, 6:26:27 AM11/25/16
to Discuss
hello everyone
i am trying to restore a saved variable in tensorflow. seems like it is very very complicated. 

i use the alexnet implementation in http://www.cs.toronto.edu/~guerzhoy/tf_alexnet/

in a python file, alexnet.py,  I define the variable
conv5W = tf.Variable(net_data["conv5"][0],name='conv5w')

then, i finetune the model and i see that some of its values are changed. i save the finetuned model by typing:

saver = tf.train.Saver()
saver.save(sess,"modelname.ckpt")

after that, i open a new ipython console and run:

from alexnet import *
sess=tf.InteractiveSession()
new_saver = tf.train.import_meta_graph("modelname.ckpt.meta")
new_saver.restore(sess, "modelname.ckpt")

after that, when i try to retrieve the values of the variables with:
conv5W.eval(session=sess)

it yields:
FailedPreconditionError: Attempting to use uninitialized value conv5w
[[Node: conv5w/_98 = _Send[T=DT_FLOAT, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_4_conv5w", _device="/job:localhost/replica:0/task:0/gpu:0"](conv5w)]]
[[Node: conv5w/_99 = _Recv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_4_conv5w", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

on the other hand, if I initialize variable with:
init = tf.initialize_all_variables()
sess.run([init]) ,

this time it yields the initial values in net_data["conv5"][0], not the finetuned ones



Martin Wicke

unread,
Nov 28, 2016, 2:26:40 PM11/28/16
to emrec...@gmail.com, Discuss
This is a question best asked on StackOverflow. It should work if you initialize first, then restore.

--
You received this message because you are subscribed to the Google Groups "Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss+unsubscribe@tensorflow.org.
To post to this group, send email to dis...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/discuss/a0ce2117-46c4-4d13-8053-ed0764faa5c9%40tensorflow.org.

Reply all
Reply to author
Forward
0 new messages