检查输入时出错:期望input_32具有3个维度,但数组的形状为(1000,12)

时间:2019-04-29 22:18:20

标签: python-3.x keras

我有以下问题。通过实现以下代码

def model(inp_size):
    inp = Input(shape=(inp_size, 1))

    x1 = Dense(50, activation='elu')(inp)
    x1 = Dense(20, activation='elu')(x1)
    x1 = Dense(1, activation = 'linear')(x1)

    x2 = Dense(50, activation='elu')(inp)
    x2 = Dense(20, activation='elu')(x2)
    x2 = Dense(1, activation = 'linear')(x2)

    x3 = Dense(50, activation='elu')(inp)
    x3 = Dense(20, activation='elu')(x3)
    x3 = Dense(1, activation = 'linear')(x3)

    x4 = Dense(50, activation='elu')(inp)
    x4 = Dense(20, activation='elu')(x4)
    x4 = Dense(1, activation = 'linear')(x4)



    x1 = Lambda(lambda x: x * 3)(x1)
    x2 = Lambda(lambda x: x * 2)(x2)
    x3 = Lambda(lambda x: x * 2)(x3)
    x4 = Lambda(lambda x: x * 1)(x4)

    out = Add()([x1, x2, x3, x4])

    return Model(inputs = inp, outputs = out)

X_train = np.random.rand(1000,12)
y_train =np.random.rand(1000,1)
NN_model = model(X_train.shape[1])
NN_model.compile(loss='mean_absolute_error', optimizer='Adamax', metrics=['mean_absolute_error'])
#N_model.summary()
NN_model.fit(X_train, y_train, epochs=10,verbose = 1)
predictions = NN_model.predict(X_test)



print('NN MAE = ', MAE)

我得到了错误

ValueError: Error when checking input: expected input_34 to have 3 dimensions, but got array with shape (1000, 12)

我没有得到,因为我认为我将输入层定义为inp = Input(shape =(inp_size,1)),每个数据集应为1000,

很抱歉,如果这是一个非常幼稚的问题,我仍然是初学者 谢谢!

0 个答案:

没有答案