我用keras训练神经网络,输入数据的形状为(116,2,3,58),输出数据的形状为(116,2)。我收到此错误:
ValueError: Error when checking target: expected dense_3 to have 4 dimensions, but got array with shape (116, 2)
我可能做错了什么?这是我的代码:
trainingInput = np.load("trainingInput.npy")
trainingOutput = np.load("trainingOutput.npy")
inp = Input(batch_shape=(116, 2, 3, 58))
d1 = Dense(16, activation='relu')(inp)
d2 = Dense(32, activation='relu')(d1)
out = Dense(2, activation='softmax')(d2)
model = Model(inputs=inp, outputs=out)
lrSet = SGD(lr=0.01)
model.compile(loss='categorical_crossentropy', optimizer=lrSet, metrics=['accuracy'])
model.fit(trainingInput, trainingOutput, batch_size=16, epochs=50, verbose=1, validation_split=0.1)
答案 0 :(得分:0)
密集是一个完全连接的层。它不会改变输入的形状。如果你想使用Dense,你应该调整大小(116,2,3,68) - > (116,2 * 3 * 68)