火车和验证数据的形状:
x_train (340, 63, 3)
y_train (340,)
x_val (38, 63, 3)
y_val (38,)
超参数
HIDDEN_NODES = 3
OUTPUT_NURONS = 1
ACTIVATION = 'sigmoid'
LOSS = "binary_crossentropy"
OPTIMIZER = 'adam'
型号:
model = Sequential()
model.add(LSTM(HIDDEN_NODES, return_sequences=True, input_shape=x_train.shape[-2:],
activation=ACTIVATION))
model.add(Dropout(0.2))
model.add(Dense(units=OUTPUT_NURONS))
model.compile(loss=LOSS, optimizer=OPTIMIZER, metrics=['acc'])
model.fit(x_train,y_train, batch_size=10, epochs=10, validation_data=(x_val,y_val))
ValueError:传递形状为(340,1)的目标数组以输出形状为(None,63,1),同时用作损失binary_crossentropy
。这种损失会导致目标与输出的形状相同。