TensorFlow Session 用於交互式上下文,例如 shell。
用法
tf.compat.v1.InteractiveSession(
target='', graph=None, config=None
)參數
-
target(可選。)要連接的執行引擎。默認使用in-process 引擎。 -
graph(可選。)要啟動的Graph(如上所述)。 -
config(可選)ConfigProtoproto 用於配置會話。
屬性
-
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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
