2021-11-10

2021-11-10,第1张

2021-11-10

keras在训练时,报输入数据维度错误的问题

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 2 array(s), but instead got the following list of 1 arrays

1.先检查输入的维度是否有误

使用shape查看输入的数据维度和定义的模型维度是否相等

2.当维度无错误时,请检查是否时多输入或多输出

例如,当有多个输入X1, X2,…,Xn 或多个输出Y1,Y2,… ,Yn时
应当将所有的输入(出)放在一个列表中
model.fit([X1, X2,…,Xn], [Y1,Y2,… ,Yn])
validation_data按同样的 *** 作

我跑的是DAE,单输入,双输出,所以将输出写在一个列表中

def DAE(sizes):
    features = sizes[0]
    classes = sizes[-1]
    input_tensor = layers.Input([features, ], name="input")
    x = layers.Dropout(0.2)(input_tensor)
    for i in range(1, len(sizes)-1):
        x = layers.Dense(units=sizes[i], activation=activations.relu)(x)
    
    out1 = layers.Dense(units=features, activation=activations.relu, name="decode")(x)
    out2 = layers.Dense(units=classes, activation=activations.softmax, name="class")(x)
    
    model = Model(input_tensor, [out1, out2])
    
    return model
dae_model = DAE(sizes)
dae_model.compile(optimizer=optimizers.adam(),
                  loss={"decode":losses.mse, "class":losses.categorical_crossentropy},
                  loss_weights={"decode":lambda1, "class":lambda2},
                  metrics=["accuracy"])
dae_model.summary()


dae_model.fit(x_train_2_axis, [x_train_2_axis, y_train_2_axis], 
              batch_size=32, epochs=10, 
              validation_data=(x_test_2_axis, [x_test_2_axis, y_test_2_axis]))
					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5437087.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存