我最近嘗試使用 MirroredStrategy 進行培訓。相關代碼為:
dataset = tf.data.Dataset.from_tensor_slices((samples, feature))
model.fit(dataset,
batch_size=500, epochs=150,
#callbacks=[tensorboard_callback]
)
資料集列印是:
Out[1]: <TensorSliceDataset element_spec=(TensorSpec(shape=(16, 17, 10), dtype=tf.float64, name=None), TensorSpec(shape=(1000,), dtype=tf.float32, name=None))>
這是正確的尺寸,但我收到以下錯誤:
ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 16, 17, 10), found shape=(8, 17, 10)
這很奇怪,因為檔案說該策略會將第一個維度而不是第二個維度減半,它應該沿第一個軸將資料集拆分為 2。
有誰知道是什么問題?
旁注:變數“特征”的名稱具有誤導性,它應該是標簽。
uj5u.com熱心網友回復:
Keras API 雖然在很多方面都很棒,但也很長,尤其是 fit 嚴重超載。
在您的情況下,請不要在 fit... 中使用 batch_size arg... 批處理您的資料集,而不是通過
資料集 = dataset.batch(500)。
請參閱 keras fit 的檔案:
batch_size Integer or None. Number of samples per gradient update. If unspecified, batch_size will default to 32. Do not specify the batch_size if your data is in the form of datasets, generators, or keras.utils.Sequence instances (since they generate batches).
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/414253.html
標籤:
上一篇:將數值張量流資料集適配為文本向量
