我正在尝试使用 Keras 构建人工神经网络。模型的输入尺寸为 (5, 5, 2),而输出尺寸为 (5,5)。在运行 keras.fit() 函数时,我遇到以下错误:
ValueError: Error when checking target: expected dense_3 to have 4 dimensions, but got array with shape (5, 5)
这是我正在执行的代码
from keras.models import Sequential
from keras.layers import Dense, Flatten
import matplotlib.pyplot as plt
from keras.callbacks import EarlyStopping, ModelCheckpoint
model = Sequential()
model.add(Dense(1000, input_shape=(5, 5, 2), activation="relu"))
model.add(Dense(1000, activation="relu"))
model.add(Dense(2), output_shape=(5,5))
model.summary()
model.compile(optimizer="adam",loss="mse", metrics = ["mse"])
monitor_val_acc = EarlyStopping(monitor="loss", patience = 10)
history = model.fit(trainX, trainYbliss, epochs=1000, validation_data=(testX, testY), callbacks = [monitor_val_acc], verbose = 1)
clinical = model.predict(np.arange(0, len(testY)))
这是网络的架构:
Layer (type) Output Shape Param #
=================================================================
dense_1 (Dense) (None, 5, 5, 1000) 3000
_________________________________________________________________
dense_2 (Dense) (None, 5, 5, 1000) 1001000
_________________________________________________________________
dense_3 (Dense) (None, 5, 5, 1) 1001
=================================================================
Total params: 1,005,001
Trainable params: 1,005,001
Non-trainable params: 0
_________________________________________________________________
模型应该基于 (5,5,2) 数组输出 (5,5) 数组,但在最低隐藏层失败。我该如何解决这个问题?
开满天机
慕尼黑8549860
相关分类