TensorFlow中的常用函数

Tensorflow依赖于一个高效的C++后端来进行计算。与后端的这个连接叫做session。一般而言,使用TensorFlow程序的流程是先创建一个图,然后在session中启动它。

tf.Tensor.eval函数:

文档中的解释如下:

eval

 
 
eval(
    feed_dict
=None,
    session
=None
)
Evaluates this tensor in a Session.
Calling this method will execute all preceding operations that produce the inputs needed for the operation that produces this tensor.
N.B. Before invoking Tensor.eval(), its graph must have been launched in a session, and either a default session must be available, or session must be specified explicitly.
Args:
  • feed_dict: A dictionary that maps Tensor objects to feed values. See tf.Session.run for a description of the valid feed values.
  • session: (Optional.) The Session to be used to evaluate this tensor. If none, the default session will be used.
Returns:
A numpy array corresponding to the value of this tensor.
翻译一下就是:

在一个会话当中求张量Tensor的值,这个方法将会执行在这之前产生这个张量的输入所必须的操作,在运行张量前,图必须已经在会话中启动,并且要么一个默认的会话是可用的,要么必须明确指定会话。

其中session这个参数是可选的,没有指定的话,就会使用默认的会话

猜你喜欢

转载自blog.csdn.net/shiheyingzhe/article/details/80789595