為 tf.data 啟用調試模式。
用法
tf.data.experimental.enable_debug_mode()
拋出
-
ValueError
從圖形模式調用時。
pdb 模塊的示例用法:
import tensorflow as tf
import pdb
tf.data.experimental.enable_debug_mode()
def func(x):
# Python 3.7 and older requires `pdb.Pdb(nosigint=True).set_trace()`
pdb.set_trace()
x = x + 1
return x
dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3])
dataset = dataset.map(func)
for item in dataset:
print(item)
調試模式的效果是two-fold:
1) 任何會在輸入管道執行中引入異步、並行或非確定性的轉換都將被迫同步、順序和確定性地執行。
2) 任何傳遞給 tf.data 轉換的用戶定義函數,例如 map
都將被包裝在 tf.py_function
中,以便它們的主體作為 Python 函數執行 "eagerly",而不是跟蹤的 TensorFlow 圖,這是默認的行為。請注意,即使啟用了調試模式,仍會跟蹤用戶定義的函數以推斷其輸出的形狀和類型;因此,任何print
語句或斷點都將在輸入管道實際執行之前的跟蹤期間觸發一次。
注意:由於調試模式設置會影響 tf.data 輸入管道的構建,因此應在任何 tf.data 定義之前啟用它。
相關用法
- Python tf.data.experimental.enumerate_dataset用法及代碼示例
- Python tf.data.experimental.RandomDataset.group_by_window用法及代碼示例
- Python tf.data.experimental.SqlDataset.enumerate用法及代碼示例
- Python tf.data.experimental.make_saveable_from_iterator用法及代碼示例
- Python tf.data.experimental.SqlDataset.zip用法及代碼示例
- Python tf.data.experimental.Counter用法及代碼示例
- Python tf.data.experimental.SqlDataset.shard用法及代碼示例
- Python tf.data.experimental.CsvDataset.window用法及代碼示例
- Python tf.data.experimental.RandomDataset.cache用法及代碼示例
- Python tf.data.experimental.SqlDataset.snapshot用法及代碼示例
- Python tf.data.experimental.CsvDataset.apply用法及代碼示例
- Python tf.data.experimental.DatasetInitializer用法及代碼示例
- Python tf.data.experimental.ignore_errors用法及代碼示例
- Python tf.data.experimental.unbatch用法及代碼示例
- Python tf.data.experimental.RandomDataset.map用法及代碼示例
- Python tf.data.experimental.CsvDataset.flat_map用法及代碼示例
- Python tf.data.experimental.assert_cardinality用法及代碼示例
- Python tf.data.experimental.CsvDataset.random用法及代碼示例
- Python tf.data.experimental.save用法及代碼示例
- Python tf.data.experimental.CsvDataset.cardinality用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.data.experimental.enable_debug_mode。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。