FailedPreconditionError: Attempting to use uninitialized in Tensorflow
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) self.init_embeddings() def init_embeddings(self): """ some variables init """
When saving variables, the saver does not realize other variable initialized in func
init_embedding. Thus these variables cannot be restored from ckpt files.
When using them, it will throw
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power in which the
beta1_power is the unlucky one.
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.
This exception is most commonly raised when running an operation that reads a tf.Variable before it has been initialized.