TensorFlow Running program error FAILEDPRECONDITIONERROR

Source: Internet
Author: User

1 failedpreconditionerror Error phenomena

When running TensorFlow error, the error statement is as follows:

Failedpreconditionerror (see above for Traceback): Attempting to use uninitialized value Variable
[[Node:variable/read = _mklidentity[t=dt_float, _kernel= "Mklop", _device= "/job:localhost/replica:0/task:0/device: Cpu:0 "] (Variable, DMT/_0)]

A straightforward translation of the cause of the error (letter, elegance, and accuracy of the serious missing):

Conditional preprocessing failure error (see backtracking above): Attempt to use an uninitialized value variable.

2 Failedpreconditionerror Error Analysis of 2.1 Failedpreconditionerror

To view the error class source code:

class Failedpreconditionerror (operror):   """ Operation was rejected because the system are not in a state to execute it.  This exception was most commonly raised when running an operation that  reads a @{tf. Variable}  before it has been initialized.  @@__init__  "" "  def__init__(self, node_def, OP, message):     """ creates a ' failedpreconditionerror '. """     Super (Failedpreconditionerror, self). __init__ (Node_def, OP, message, failed_precondition)

Note the meaning can be understood as:

The operation was rejected because the system is not in the execution state.

At @ {TF. This exception is typically thrown when a read operation is run before initialization of Variable.

Source code for 2.2 Global_variables_initializer

View the source code of the Global_variables_initializer function

def Global_variables_initializer ():   """ Returns an Op that initializes global variables.  This was just a shortcut for ' Variables_initializer (Global_variables ()) '  Returns: An    Op that initializes global VA Riables in the graph.   """  if context.executing_eagerly ():     return control_flow_ops.no_op (name="global_variables_initializer" )  return Variables_initializer (Global_variables ())

Traceability, view Variable_initializer function source code.

defVariables_initializer (Var_list, name="Init"):  """Returns A Op that initializes a list of variables. After your launch the graph in a session, you can run the returned Op to initialize all the variables in ' var_list '.  This Op runs all the initializers of the variables in ' var_list ' in parallel.  Calling ' Initialize_variables () ' is equivalent-passing the list of initializers to ' Group () '. If ' var_list ' is empty, however, the function still returns a Op that can be run.  That Op just has no effect.    Args:var_list:List of ' Variable ' objects to initialize.  Name:optional name for the returned operation.  Returns:an Op that run the initializers of the specified variables. """  ifVar_list and  notcontext.executing_eagerly ():returnControl_flow_ops.group (*[v.initializer forVinchVar_list], name=name)returnControl_flow_ops.no_op (Name=name)

View the Global_variables () function source code.

defGlobal_variables (scope=None):"""Returns Global variables. Global variables is variables that is shared across machines in a distributed environment. The ' Variable () ' constructor or ' get_variable () ' automatically adds new variables to the graph collection ' Graphkeys.glo  Bal_variables '.  This convenience function returns the contents of that collection. An alternative to global variables is local variables. See @{tf.local_variables} args:scope: (Optional.) A string. If supplied, the resulting list is filtered to include only items whose ' name ' attribute matches ' scope ' using ' Re.match '. Items without a ' name ' attribute is never returned if a scopes is supplied.  The choice of ' re.match ' means, a ' scope ' without special tokens filters by prefix.  Returns:a List of ' Variable ' objects. """  returnOps.get_collection (OPS. Graphkeys.global_variables, Scope)
2.3 Global variable initialization analysis 2.3.1 variables

The TensorFlow variable is the best way to represent the shared persistence state that the program handles.

We pass TF. The variable class action variable. Tf. Variable represents the amount of the value that can be changed by running an operation on it.

With TF. Tensor objects are different, TF. Variable exist outside the context of a single tf.session (). Run () call.

Within the TensorFlow, TF. The variable stores the persistence tensor. The specific Operation (OP) allows you to read and modify the values of the tensor. These modifications are in multiple TF. The Session () is visible between the sessions, so for a TF. Variable, more than one worker can see the same value.

2.3.2 Variable Collection

Since the disconnected parts of the TensorFlow program may need to create variables, it is sometimes useful to have access to all variables in one way. To do this, TensorFlow provides collections , which are named lists of tensor or other objects, such as tf.Variable instances.

By default, each tf.Variable is placed in one of the following two collections:

    • tf.GraphKeys.GLOBAL_VARIABLES-variables that can be shared across multiple devices,
    • tf.GraphKeys.TRAINABLE_VARIABLES-TensorFlow will calculate the variable of its gradient.

If you do not want the variable to be trained, you can add it to the tf.GraphKeys.LOCAL_VARIABLES collection.

2.3.3 Initializing variables

Variables must be initialized before they can be used.

If you are programming in the low-level TensorFlow API (that is, you are explicitly creating your own diagrams and sessions), you must explicitly initialize the variables. tf.contrib.slim, tf.estimator.Estimator and Keras most advanced frameworks will automatically initialize variables for you before training the model.

Explicit initialization is useful in other ways. It allows you to re-load the model from the checkpoint without re-running the potential resource consuming the large initializer, and to allow certainty in sharing randomly initialized variables in distributed settings.

To initialize all the available training variables at once before training starts, call tf.global_variables_initializer() . This function returns an action that is responsible for initializing tf.GraphKeys.GLOBAL_VARIABLES all the variables in the collection. Running this operation initializes all of the variables. For example:

Session.run (Tf.global_variables_initializer ()) # Now all variables is initialized.

If you do need to initialize the variable yourself, you can run the initializer action for the variable. For example:

Session.run (My_variable.initializer)

You can query which variables have not been initialized. For example, the following code prints all the variable names that have not been initialized:

Print (Session.run (Tf.report_uninitialized_variables ()))

Note that by default, tf.global_variables_initializer the initialization order of variables is not specified. Therefore, if the initial value of a variable depends on the value of another variable, there is a good chance that an error will occur . At any time, if you use a variable value in a context where not all variables are initialized (for example, by using another variable's value when initializing a variable), it is best variable.initialized_value() to use rather than variable :

v = tf.get_variable ("v", Shape= (), initializer== tf.get_variable (" W ", Initializer=v.initialized_value () + 1)

Refer to TensorFlow's official information-- variable https://www.tensorflow.org/programmers_guide/variables

Note:

Before March 02, 2017, the global variable initializes the function Initialize_all_variables (), followed by the Global_variables_initializer () function.

Reference

Processing Failedpreconditionerror, this article interprets the Failedpreconditionerror error function

TensorFlow define the wrong type of exception (verbose) Enter this article to search the Failedpreconditionerror function directly, you can see the source code snippet

The meaning of variable initialization this article is stored in the stack and heap of C + + program and proves by example analysis

Refer to TensorFlow's official information-- variable https://www.tensorflow.org/programmers_guide/variables

Tf.global_variables_initializer:https://devdocs.io/tensorflow~python/tf/global_variables_initializer

TensorFlow/tensorflow/python/ops/variables.py:https://github.com/tensorflow/ tensorflow/blob/r1.8/tensorflow/python/ops/variables.py

The method of parameter initialization in TensorFlow

Failedpreconditionerror TensorFlow

TensorFlow Running program error FAILEDPRECONDITIONERROR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.