TensorFlow Session
用于交互式上下文,例如 shell。
用法
tf.compat.v1.InteractiveSession(
target='', graph=None, config=None
)
参数
-
target
(可选。)要连接的执行引擎。默认使用in-process 引擎。 -
graph
(可选。)要启动的Graph
(如上所述)。 -
config
(可选)ConfigProto
proto 用于配置会话。
属性
-
graph
在此会话中启动的图表。 -
graph_def
底层 TensorFlow 图的可序列化版本。 -
sess_str
此会话将连接到的 TensorFlow 进程。
与常规Session
的唯一区别是InteractiveSession
将自身安装为构造时的默认会话。 tf.Tensor.eval
和 tf.Operation.run
方法将使用该会话来运行操作。
这在交互式 shell 和 IPython 笔记本中很方便,因为它避免了必须传递显式 Session
对象来运行操作。
例如:
sess = tf.compat.v1.InteractiveSession()
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
# We can just use 'c.eval()' without passing 'sess'
print(c.eval())
sess.close()
请注意,在with
语句中创建常规会话时,它会将自身安装为默认会话。非交互式程序中的常见用法是遵循该模式:
a = tf.constant(5.0)
b = tf.constant(6.0)
c = a * b
with tf.compat.v1.Session():
# We can also use 'c.eval()' here.
print(c.eval())
相关用法
- Python tf.compat.v1.InteractiveSession.partial_run用法及代码示例
- Python tf.compat.v1.InteractiveSession.run用法及代码示例
- Python tf.compat.v1.InteractiveSession.list_devices用法及代码示例
- Python tf.compat.v1.InteractiveSession.as_default用法及代码示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代码示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代码示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代码示例
- Python tf.compat.v1.Variable.eval用法及代码示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代码示例
- Python tf.compat.v1.layers.conv3d用法及代码示例
- Python tf.compat.v1.strings.length用法及代码示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代码示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代码示例
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代码示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代码示例
- Python tf.compat.v1.variable_scope用法及代码示例
- Python tf.compat.v1.data.experimental.SqlDataset.as_numpy_iterator用法及代码示例
- Python tf.compat.v1.distributions.Bernoulli.covariance用法及代码示例
- Python tf.compat.v1.placeholder用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.InteractiveSession。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。