tensorflow.python.client.session.BaseSession.run

Function

Executes a computational graph.

Prototype

1
def run(self, fetches, feed_dict=None, options=None, run_metadata=None)

Parameters

Parameter

Type

Mandatory/Optional

Description

fetches

  • str
  • tf.Operation
  • tf.Variable
  • tf.Tensor
  • tf.sparse.SparseTensor
  • list
  • tuple
  • dict

Mandatory

Runs the operation or obtains the tensor.

feed_dict

  • tf.Variable
  • tf.Tensor
  • tf.sparse.SparseTensor
  • list
  • tuple
  • dict

Optional

Overwrites the tensor value in the graph.

options

tf.compat.v1.RunOptions

Optional

Controls the behavior of a specific step.

run_metadata

tf.compat.v1.RunMetadata

Optional

Collects non-tensor output at a specific step.

Return Value

  • Success: If fetches is a single element, a single element value is returned. If fetches is a list, a list is returned. If fetches is a dict, a dict with the same key is returned.
  • Failure: An exception is thrown.

Example

The following provides only an example of the usage process.

1
2
3
4
5
6
7
8
#1. Import required libraries.
import tensorflow as tf
from mx_rec.util.initialize import init
# 2. Build a computational graph.
# ...
# 3. Call the API for training.
with tf.compat.v1.Session() as sess:
     sess.run([train_ops])      # train_ops is the training operator built in the computational graph.