Failedpreconditionerror: Attempting to Use Uninitialized in Tensorflow

FailedPreconditionError: Attempting to use uninitialized value W

Reason for Accuracy giving NaNs : You have split the training data into X_train and X_test due to which your indices got disturbed and the train dataset become quite random with respect to the indices and when you feed your X_train batches-wise, the indices from [0:50] do not exist while training and hence you end up feeding nothing to you model.

Before training the model, do this :

X_test.reset_index(drop=True)
Y_test.reset_index(drop=True)

This will reset your indices and drop=True will prevent the original indices from becoming another column in your transformed dataframe.

As far as the Weights and Biases are concerned, DO NOT use another session for testing the model because all your trained variables will be lost in this session and hence the error Attempting to use uninitialized value W_4 will occur.

You can also try saving your variables for the sake of convenience.

Also, refer this for your logits part : here

Tensorflow : FailedPreconditionError: Attempting to use uninitialized value conv2d_transpose/bias

The model needed to be called before the tf.global_variabels_initializer() is used
ie. the train function is changed as below

def train(self, input_img):
plh = tf.placeholder(dtype=tf.float32, shape=(None, 84, 150, 3), name="input_img")

with tf.variable_scope("test", reuse=tf.AUTO_REUSE):
var_dict_1 = {
"v1": tf.get_variable("v1", shape=(2, 2, 3, 32), initializer=tf.contrib.layers.xavier_initializer())
}
bias_1 = {
"b1": tf.get_variable("b1", shape=32, initializer=tf.contrib.layers.xavier_initializer())
}

"""model is called before variable initialization"""

model = self.__model_1(plh, var_dict_1, bias_1)

init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
out_p = sess.run([model], feed_dict={plh: [input_img]})
return out_p

the line given below:

out_p = sess.run([self.__model_1(plh, var_dict_1, bias_1)], feed_dict={plh: [input_img]})

is changed into

out_p = sess.run([model], feed_dict={plh: [input_img]})

Tensorflow FailedPreconditionError: Attempting to use uninitialized value beta1_power

This error generally occurs when you haven't initialized the optimizer.
So just add self.optimize before you initialize all the global variables.

Your code should look like this.

def __init__(self, input, labels, dataset):

self.input = input
self.true_labels = labels

#'dataset' is an instance of a class that
#I am using to read the training images
self.data = dataset

self.build()

self._optimize = None

self.sess = tf.Session()
self.optimize()
self.sess.run(tf.global_variables_initializer())

FailedPreconditionError: Attempting to use uninitialized value conv2d_1/kernel with Tensorflow/Python

This is happening because you are running the initializer before building the graph. Ideally you should build the Graph before creating a Session. Try this

with tf.Graph().as_default():
i = PlantUtils().create_instance('ara2013_plant001_rgb.png', 'ara2013_plant001_label.png', 500, 530, 100, 106, 1, 1, 1)
input_image = i[0] # It is a 500 * 530 * 3 tensor
b = Create_CNN().create_cnn(input=input_image, kernelSize=3, kernelStride=1, nChannels=30)
x = tf.argmax(input=b, axis=1)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print sess.run(x)

FailedPreconditionError: Attempting to use uninitialized value

You need to create the variable initializer in the end, when you are done creating the graph.

When you call tf.global_variable_initializer(), it takes all the trainable variables that have been created up until that point. So, if you define this before creating your layers (and variables), those new variables won't be added to this initializer.

Tensorflow: Attempting to use uninitialized value beta1_power

Change the order of these two lines:

opt=tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(loss)
init=tf.global_variables_initializer()

Since AdamOptimizer has it's own variables, you should define the initilizer init after opt, not before.

TensorFlow: “Attempting to use uninitialized value” in variable initialization

You also need to initialise the local variables hidden in the tf.metrics.recallmethod.

For example, this piece of code would work:

init_g = tf.global_variables_initializer()
init_l = tf.local_variables_initializer()
with tf.Session() as sess:
sess.run(init_g)
sess.run(init_l)

Tensorflow FailedPreconditionError: Attempting to use uninitialized value Variable

with tf.Session() as sess:
...
print('test accuracy %g' % accuracy.eval(feed_dict={
x: mnist.test.images, y_:mnist.test.labels, keep_prob: 1.0}))

when use tf.Session You should put print method in the with block for setting sess when run eval.

For InteractiveSession it will set the default session, so you can excute eval and run with this default session.



Related Topics



Leave a reply



Submit