tensorflow Variable Initialization error : Attempt

2020-05-09 10:18发布

问题:

Why is this happening? Error message - Attempting to uninitialized Variable Error here is my source: source - Learning .JPG Image in computer using tensorflow

I don't know why this error occur... I already used two types of variable initialization function:

  1. tf.global_variables_initializer()
  2. tf.local_variables_initializer()

回答1:

You should use tf.global_variables_initializer() and invoke it after you defined all the variables, not before. The simplest thing would be to do simply:

with tf.Session() as sess:
  sess.run(tf.global_variables_initializer())
  ...