sess.run tensorflow

tf.compat.v1.Session
A class for running TensorFlow operations.

run(
    fetches, feed_dict=None, options=None, run_metadata=None
)

Runs operations and evaluates tensors in fetches.

This method runs one "step" of TensorFlow computation, 
by running the necessary graph fragment to execute every Operation 
and evaluate every Tensor in fetches, substituting the values in 
feed_dict for the corresponding input values.

The fetches argument may be a single graph element, or an arbitrarily 
nested list, tuple, namedtuple, dict, or OrderedDict containing graph 
elements at its leaves.

The optional feed_dict argument allows the caller to override the 
value of tensors in the graph. Each value in feed_dict must be 
convertible to a numpy array of the dtype of the corresponding key.

The optional options argument expects a [RunOptions] proto. 
The options allow controlling the behavior of this particular step 
(e.g. turning tracing on).

The optional run_metadata argument expects a [RunMetadata] proto. 
When appropriate, the non-Tensor output of this step will be 
collected there. For example, when users turn on tracing in options, 
the profiled info will be collected into this argument and passed 
back.

Here is what the above code is Doing:
1. First, it creates a session object.
2. Then, it runs the session, evaluating the graph.
3. Finally, it closes the session.

The run() method takes three arguments:

1. fetches: The desired outputs of the computation (e.g., the values of the variables to be computed).
2. feed_dict: A dictionary that maps graph elements to values (e.g., the inputs of the computation).
3. options: Run options (e.g., trace level).

The fetches and feed_dict arguments can be either a single graph element or a list of graph elements.

The options argument is used to control the behavior of the session (e.g., to turn tracing on).

The run() method returns the values of the fetches.

If you want to evaluate the graph without running a session, you can use the eval() method.

The eval() method takes three arguments:

1. fetches: The desired outputs of the computation (e.g., the values of the variables to be computed).
2. feed_dict: A dictionary that maps graph elements to values (e.g., the inputs of the computation).
3. session: The session to be used to run the computation.

The fetches and feed_dict arguments can be either a single graph element or a list of graph elements.

The eval() method returns the values of the fetches.

If you want to run the graph in a session but don’t want to evaluate any outputs, you can use the run() method.

The run() method takes three arguments:

1. fetches: The desired outputs of the computation (e.g., the values of the variables to be computed).
2. feed_dict: A dictionary that maps graph elements to values (e.g., the inputs of the computation).
3. session: The session to be used to run the computation.

The fetches and feed_dict arguments can be either a single graph element or a list of graph elements.

The run() method returns the values of the fetches.