Tensorflow: Las nuevas variables agregadas no se pueden guardar

Creado en 24 may. 2016  ·  1Comentario  ·  Fuente: tensorflow/tensorflow

Probé ejecutando estas 3 piezas de código respectivamente.

Primero, inicie algunas variables y guarde.

import tensorflow as tf

sess = tf.InteractiveSession()
v1 = tf.Variable(1,name="v1")
v2 = tf.Variable(2,name="v2")
sess.run(tf.initialize_all_variables())
saver = tf.train.Saver()
saver.save(sess,'v12.ckpt')

Luego, restaure la sesión, agregue una variable más y guarde.

import tensorflow as tf

sess = tf.InteractiveSession()
v1 = tf.Variable(1,name="v1")
v2 = tf.Variable(2,name="v2")
saver = tf.train.Saver()
saver.restore(sess,'v12.ckpt')  #works fine here

v3 = tf.Variable(3,name="v3")
sess.run(tf.initialize_variables([v3]))

saver.save(sess,'v123.ckpt')

print v3.eval() #show value without problem

Luego, restáurelos.

import tensorflow as tf

sess = tf.InteractiveSession()
v1 = tf.Variable(1,name="v1")
v2 = tf.Variable(2,name="v2")
v3 = tf.Variable(3,name="v3")

saver = tf.train.Saver()
saver.restore(sess,'v123.ckpt') #error here

Este es el error:

tensorflow.python.framework.errors.NotFoundError: Tensor name "v3" not found in checkpoint files v123.ckpt [[Node: save/restore_slice_2 = RestoreSlice[dt=DT_INT32, preferred_shard=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/restore_slice_2/tensor_name, save/restore_slice_2/shape_and_slice)]] Caused by op u'save/restore_slice_2'

¿Cuál es el problema aquí?

Estoy usando la versión r0.8 en Ubuntu16.04

Comentario más útil

Cuando crea un tf.train.Saver sin argumentos, implícitamente usará el conjunto actual de variables _ en el momento de la construcción de Saver_ cuando guarde y restaure. Si agrega una nueva variable (por ejemplo, v3 en su segundo bloque de código), debe crear un nuevo tf.train.Saver para guardarlo.

import tensorflow as tf

sess = tf.InteractiveSession()
v1 = tf.Variable(1,name="v1")
v2 = tf.Variable(2,name="v2")
saver = tf.train.Saver()
saver.restore(sess,'v12.ckpt')  #works fine here

v3 = tf.Variable(3,name="v3")
sess.run(tf.initialize_variables([v3]))

saver_with_v3 = tf.train.Saver()
saver_with_v3.save(sess,'v123.ckpt')

>Todos los comentarios

Cuando crea un tf.train.Saver sin argumentos, implícitamente usará el conjunto actual de variables _ en el momento de la construcción de Saver_ cuando guarde y restaure. Si agrega una nueva variable (por ejemplo, v3 en su segundo bloque de código), debe crear un nuevo tf.train.Saver para guardarlo.

import tensorflow as tf

sess = tf.InteractiveSession()
v1 = tf.Variable(1,name="v1")
v2 = tf.Variable(2,name="v2")
saver = tf.train.Saver()
saver.restore(sess,'v12.ckpt')  #works fine here

v3 = tf.Variable(3,name="v3")
sess.run(tf.initialize_variables([v3]))

saver_with_v3 = tf.train.Saver()
saver_with_v3.save(sess,'v123.ckpt')
¿Fue útil esta página
0 / 5 - 0 calificaciones