W3cubDocs

/TensorFlow Python

tf.contrib.util.constant_value(tensor)

tf.contrib.util.constant_value(tensor)

See the guide: Utilities (contrib) > Miscellaneous Utility Functions

Returns the constant value of the given tensor, if efficiently calculable.

This function attempts to partially evaluate the given tensor, and returns its value as a numpy ndarray if this succeeds.

TODO(mrry): Consider whether this function should use a registration mechanism like gradients and ShapeFunctions, so that it is easily extensible.

NOTE: If constant_value(tensor) returns a non-None result, it will no longer be possible to feed a different value for tensor. This allows the result of this function to influence the graph that is constructed, and permits static shape optimizations.

Args:

  • tensor: The Tensor to be evaluated.

Returns:

A numpy ndarray containing the constant value of the given tensor, or None if it cannot be calculated.

Raises:

  • TypeError: if tensor is not an ops.Tensor.

Defined in tensorflow/python/framework/tensor_util.py.

© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/contrib/util/constant_value