输入维度错误 - Keras
Error in Input Dimensions - Keras
我正在使用 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)
Dense 是 full-connected 层。它不会改变输入的形状。如果你想使用 Dense,你应该调整 (116,2,3,68) -> (116,2*3*68)
我正在使用 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)
Dense 是 full-connected 层。它不会改变输入的形状。如果你想使用 Dense,你应该调整 (116,2,3,68) -> (116,2*3*68)