TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
executing_eagerly()用於檢查在當前線程中是否啟用了急切執行。默認情況下,啟用急切執行,因此在大多數情況下它將返回true。在以下情況下將返回false:
- 如果它是在tensorflow.function內部執行的,並且之前未調用tf.init_scope或tf.config.experimental_run_functions_eagerly(True)。
- 在tensorflow.dataset的轉換函數中執行。
- tensorflow.compat.v1.disable_eager_execution()被調用。
用法:tensorflow.executing_eagerly()
參數:這不接受任何參數。
返回:如果啟用了急切執行,則返回true,否則返回false。
範例1:
Python3
# Importing the library
import tensorflow as tf
# Checking eager execution
res = tf.executing_eagerly()
# Printing the result
print('res:', res)
輸出:
res: True
範例2:此示例檢查有無init_scope的tensorflow.function的急切執行情況。
Python3
# Importing the library
import tensorflow as tf
@tf.function
def gfg():
with tf.init_scope():
# Checking eager execution inside init_scope
res = tf.executing_eagerly()
print("res 1:", res)
# Checking eager execution outside init_scope
res = tf.executing_eagerly()
print("res 2:", res)
gfg()
輸出:
res 1:True res 2:False
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.executing_eagerly()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。