FailedPreconditionError: Attempting to use uninitialized in Tensorflow

Web Solution

Answer from < mrry >

The FailedPreconditionError arises because the program is attempting to read a variable (named “Variable_1”) before it has been initialized. In TensorFlow, all variables must be explicitly initialized, by running their “initializer” operations. For convenience, you can run all of the variable initializers in the current session by executing the following statement before your training loop.

Answer from < Salvador Dali >

This exception is most commonly raised when running an operation that reads a tf.Variable before it has been initialized.

My Case

In my case, when I wrote the __init__ func in class Model, I claimed more variables after initialized the saver with tf.gloabl_variables(). It seems like :

import tensorflow as tf

class Model(object):
    def __init__(self, hparmas):
        self.hparams = hparmas
        """ some variables init """
        self.saver = tf.train.Saver(tf.global_variables(), max_to_keep = self.hparams.max_to_keep)

    def init_embeddings(self):
        """ some variables init """

When saving variables, the saver does not realize other variable initialized in func init_embedding. Thus after restore step, these variables cannot be restored from ckpt files. When using them, it will throw FailedPreconditionError like tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power in which the beta1_power is the unlucky one.


电子邮件地址不会被公开。 必填项已用*标注