我試圖模仿這里提供的聯合學習實作:Working with tff's clientData以便清楚地理解代碼。我到了需要澄清的地方。
def preprocess_dataset(dataset):
"""Create batches of 5 examples, and limit to 3 batches."""
def map_fn(input):
return collections.OrderedDict(
x=tf.reshape(input['pixels'], shape=(-1, 784)),
y=tf.cast(tf.reshape(input['label'], shape=(-1, 1)), tf.int64),
)
return dataset.batch(5).map(
map_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE).take(5)
dataset.batch(5)指的是什么?這些批次是否正在從資料中獲取訓練,而 3 個用于測驗?- 是什么
.take(5)意思?
uj5u.com熱心網友回復:
在這一行:
dataset.batch(5).map(
map_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE).take(5)
您首先將樣本dataset分成 5 個批次。然后,您將該map_fn函式應用于每個批次dataset(一次 5 個樣本)。最后,使用dataset.take(5),您將從 中回傳 5 個批次dataset,其中每個批次有 5 個樣本。
在您鏈接的示例中,client_data包含多個tf資料集。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/437205.html
標籤:Python 张量流 机器学习 张量流数据集 张量流联合
上一篇:TensorFlow版本不匹配
