Tag Archives: failed Precondition Error

How to Solve failed Precondition Error: attempting to use uninitialized value beta1_power

Solving failed precondition error: attempting to use uninitialized value beta1_ power

Using TensorFlow to implement ctpn, the code is like this

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

Error failed precondition error: attempting to use uninitialized value beta1_ power

Traceback (most recent call last):
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call
    return fn(*args)
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power
	 [[{{node beta1_power/read}} = Identity[T=DT_FLOAT, _class=["loc:@Adam/Assign_1"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](beta1_power)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/ctpn/main/train.py", line 159, in <module>
    tf.app.run()
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/tmp/ctpn/main/train.py", line 145, in main
    input_im_info:data[2]})
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
    run_metadata_ptr)
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run
    run_metadata)
  File "/home/yiverin/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value beta1_power
	 [[node beta1_power/read (defined at /tmp/ctpn/main/train.py:127)  = Identity[T=DT_FLOAT, _class=["loc:@Adam/Assign_1"], _device="/job:localhost/replica:0/task:0/device:CPU:0"](beta1_power)]]

See attaching to use uninitialized value beta1_ The answer to this question is
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.

Done!