keras多输出softmax模型输入形状

keras多输出softmax模型输入形状,keras,neural-network,output,Keras,Neural Network,Output,我有以下型号: from keras.layers import Activation, Input, Dense from keras.models import Model from keras.layers.merge import Concatenate, concatenate input_ = Input(batch_shape=(512, 36)) x = input_ x1 = Dense(4)(x) x2 = Dense(4)(x) x3 = Dense(4)(x) x4

我有以下型号:

from keras.layers import Activation, Input, Dense
from keras.models import Model
from keras.layers.merge import Concatenate, concatenate

input_ = Input(batch_shape=(512, 36))

x = input_
x1 = Dense(4)(x)
x2 = Dense(4)(x)
x3 = Dense(4)(x)
x4 = Dense(4)(x)

model = Model(inputs=input_, outputs=[x1, x2, x3, x4])
model.compile(loss='categorical_crossentropy', optimizer='adam',  metrics=['accuracy'])
history = model.fit(X, test, epochs=20, batch_size=512, verbose=2, shuffle=False, validation_data=[X, test])
My Y具有以下格式:

 col1 col2 ... col 4
  1    0         2
  0    0         2
  2    1         1
并通过以下方式进行重塑:

y = to_categorical(Y).reshape(4, -1, 3)
但是,在运行fit命令时,出现以下错误:

ValueError: Error when checking model target: the list of Numpy arrays that 
you are passing to your model is not the size the model expected. Expected 
to see 4 array(s), but instead got the following list of 1 arrays: 
[array([[[1., 0., 0.],
    [1., 0., 0.],
    [1., 0., 0.],

假设Y是一个numpy矩阵? 试试这个:

y = [to_categorical(Y[:, col_numb]).reshape(-1, 3) for col_numb in range(Y.shape[1])]