Tensorflow: Using Adam optimizer

后端 未结 5 1853
时光取名叫无心
时光取名叫无心 2020-11-29 20:53

I am experimenting with some simple models in tensorflow, including one that looks very similar to the first MNIST for ML Beginners example, but with a somewhat larger dimen

5条回答
  •  攒了一身酷
    2020-11-29 21:31

    FailedPreconditionError: Attempting to use uninitialized value is one of the most frequent errors related to tensorflow. From official documentation, FailedPreconditionError

    This exception is most commonly raised when running an operation that reads a tf.Variable before it has been initialized.

    In your case the error even explains what variable was not initialized: Attempting to use uninitialized value Variable_1. One of the TF tutorials explains a lot about variables, their creation/initialization/saving/loading

    Basically to initialize the variable you have 3 options:

    • initialize all global variables with tf.global_variables_initializer()
    • initialize variables you care about with tf.variables_initializer(list_of_vars). Notice that you can use this function to mimic global_variable_initializer: tf.variable_initializers(tf.global_variables())
    • initialize only one variable with var_name.initializer

    I almost always use the first approach. Remember you should put it inside a session run. So you will get something like this:

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

    If your are curious about more information about variables, read this documentation to know how to report_uninitialized_variables and check is_variable_initialized.

提交回复
热议问题