tensorflow.python.client.session.BaseSession.run

功能描述

TensorFlow执行计算图的方法。

函数原型

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

参数说明

参数

类型

可选/必选

说明

fetches

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

必选

运行操作或者获取其中的Tensor

feed_dict

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

可选

覆盖图中Tensor的值

options

tf.compat.v1.RunOptions

可选

控制特定步骤的行为

run_metadata

tf.compat.v1.RunMetadata

可选

在特定步骤时,收集非张量输出

返回值说明

使用示例

以下仅提供使用流程的示例。

1
2
3
4
5
6
7
8
# 1、导入需要的库
import tensorflow as tf
from mx_rec.util.initialize import init
# 2、构建计算图
# ...
# 3、调用接口训练
with tf.compat.v1.Session() as sess:
     sess.run([train_ops])      #train_ops为构建计算图中构建的训练算子