我很難理解問題是什么。考慮以下模型:
Model: "model_8"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input (InputLayer) [(None, 15)] 0 []
dense_1 (Dense) (None, 128) 2048 ['input[0][0]']
dense_2 (Dense) (None, 1024) 132096 ['dense_1[0][0]']
dense_3 (Dense) (None, 5120) 5248000 ['dense_2[0][0]']
a_out (Dense) (None, 17) 87057 ['dense_3[0][0]']
b_out (Dense) (None, 27) 138267 ['dense_3[0][0]']
c_out (Dense) (None, 71) 363591 ['dense_3[0][0]']
d_out (Dense) (None, 29) 148509 ['dense_3[0][0]']
==================================================================================================
Total params: 6,119,568
Trainable params: 6,119,568
Non-trainable params: 0
它具有一個輸入和4個輸出一個相當簡單的模型(a_out,b_out,c_out,和d_out)。我試圖通過提供一些資料集來擬合模型:
dataset = tf.data.Dataset.from_tensor_slices((inputs, {'a_out': targets[:, 0],
'b_out': targets[:, 1],
'c_out': targets[:, 2],
'd_out': targets[:, 3]}))
的inputs和targets是兩個numpy的陣列,形狀:(525081, 15)和(525081, 4)分別。當我運行 fit 方法時:
model.fit(dataset, epochs=10, batch_size=128)
我收到以下錯誤:
ValueError: Exception encountered when calling layer "model_8" (type Functional).
Input 0 of layer "dense_1" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (15,)
Call arguments received:
? inputs=tf.Tensor(shape=(15,), dtype=float64)
? training=True
? mask=None
在我看來,發送到 的張量layer_1缺少批處理維度,這對我來說沒有意義。我構建的資料集錯了嗎?
uj5u.com熱心網友回復:
使用時tf.data,batch_size引數 in 將model.fit被忽略。
批處理應使用 的.batch()方法完成tf.data.Dataset。
在你的情況下它應該是dataset.batch(batch_size).
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/396761.html
