Reputation: 395
weights = tf.Variable(tf.truncated_normal([image_size * image_size, num_labels]))
biases = tf.Variable(tf.zeros([num_labels]))`
This is a part of the code I encountered to minimize loss using Gradient Descent in tensorflow. I understood what is going on and what tf.zeros is doing but when I tried to run the follwing code it showed an error::
sess = tf.IntearctiveSession()
tensor = tf.Variable(tf.zeros(shape=(10)))
print(tensor.eval())
sess.close()
An error occured in print(tensor.eval())
.
Can someone point out where I understood the things wrong?
Upvotes: 1
Views: 405
Reputation: 1021
Looks like you forgot to initialize your variable(s). Try this:
sess = tf.IntearctiveSession()
tensor = tf.Variable(tf.zeros(shape=(10)))
sess.run(tf.global_variables_initializer()) # Now all variables are initialized
print(tensor.eval())
sess.close()
Upvotes: 1