【发布时间】:2021-12-28 20:55:48
【问题描述】:
我很难理解问题所在。考虑以下模型:
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 的张量缺少批量维度,这对我来说没有意义。我是不是在构建我的数据集错误?
【问题讨论】:
标签: tensorflow keras