將數據集值預取到給定 device
的轉換。
用法
tf.data.experimental.prefetch_to_device(
device, buffer_size=None
)
參數
-
device
一個字符串。將預取元素的設備的名稱。 -
buffer_size
(可選。)要在device
上緩衝的元素數。默認為自動選擇的值。
返回
-
一個
Dataset
轉換函數,可以傳遞給tf.data.Dataset.apply
。
注意:盡管轉換會創建 tf.data.Dataset
,但轉換必須是輸入管道中的最終 Dataset
。
例如,
>>> dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3])
>>> dataset = dataset.apply(tf.data.experimental.prefetch_to_device("/cpu:0"))
>>> for element in dataset:
... print(f'Tensor {element} is on device {element.device}')
Tensor 1 is on device /job:localhost/replica:0/task:0/device:CPU:0
Tensor 2 is on device /job:localhost/replica:0/task:0/device:CPU:0
Tensor 3 is on device /job:localhost/replica:0/task:0/device:CPU:0
相關用法
- Python tf.data.experimental.parallel_interleave用法及代碼示例
- 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.prefetch_to_device。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。