gpt4 book ai didi

python - CNN 多输入,检查模型输入 : Expected to see 2 array(s), 时出错,但得到以下 1 个数组列表:

转载 作者:行者123 更新时间:2023-12-01 08:19:34 26 4
gpt4 key购买 nike

我想将多个输入传递给我的 CNN 模型。遵循文档并传递 2 个值,但面临上述错误。型号摘要:

__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_11 (InputLayer) (None, 300) 0
__________________________________________________________________________________________________
input_22 (InputLayer) (None, 300) 0
__________________________________________________________________________________________________
embedding_1 (Embedding) (None, 300, 100) 2173500 input_11[0][0]
__________________________________________________________________________________________________
embedding_2 (Embedding) (None, 300, 100) 2173500 input_22[0][0]
__________________________________________________________________________________________________
conv1d_1 (Conv1D) (None, 300, 128) 12928 embedding_1[0][0]
__________________________________________________________________________________________________
conv1d_2 (Conv1D) (None, 299, 128) 25728 embedding_1[0][0]
__________________________________________________________________________________________________
conv1d_3 (Conv1D) (None, 298, 128) 38528 embedding_1[0][0]
__________________________________________________________________________________________________
conv1d_4 (Conv1D) (None, 297, 128) 51328 embedding_1[0][0]
__________________________________________________________________________________________________
conv1d_7 (Conv1D) (None, 300, 128) 12928 embedding_2[0][0]
__________________________________________________________________________________________________
conv1d_8 (Conv1D) (None, 299, 128) 25728 embedding_2[0][0]
__________________________________________________________________________________________________
conv1d_9 (Conv1D) (None, 298, 128) 38528 embedding_2[0][0]
__________________________________________________________________________________________________
conv1d_10 (Conv1D) (None, 297, 128) 51328 embedding_2[0][0]
__________________________________________________________________________________________________
max_pooling1d_1 (MaxPooling1D) (None, 60, 128) 0 conv1d_1[0][0]
__________________________________________________________________________________________________
max_pooling1d_2 (MaxPooling1D) (None, 59, 128) 0 conv1d_2[0][0]
__________________________________________________________________________________________________
max_pooling1d_3 (MaxPooling1D) (None, 59, 128) 0 conv1d_3[0][0]
__________________________________________________________________________________________________
max_pooling1d_4 (MaxPooling1D) (None, 59, 128) 0 conv1d_4[0][0]
__________________________________________________________________________________________________
max_pooling1d_7 (MaxPooling1D) (None, 60, 128) 0 conv1d_7[0][0]
__________________________________________________________________________________________________
max_pooling1d_8 (MaxPooling1D) (None, 59, 128) 0 conv1d_8[0][0]
__________________________________________________________________________________________________
max_pooling1d_9 (MaxPooling1D) (None, 59, 128) 0 conv1d_9[0][0]
__________________________________________________________________________________________________
max_pooling1d_10 (MaxPooling1D) (None, 59, 128) 0 conv1d_10[0][0]
__________________________________________________________________________________________________
concatenate_1 (Concatenate) (None, 237, 128) 0 max_pooling1d_1[0][0]
max_pooling1d_2[0][0]
max_pooling1d_3[0][0]
max_pooling1d_4[0][0]
__________________________________________________________________________________________________
concatenate_2 (Concatenate) (None, 237, 128) 0 max_pooling1d_7[0][0]
max_pooling1d_8[0][0]
max_pooling1d_9[0][0]
max_pooling1d_10[0][0]
__________________________________________________________________________________________________
conv1d_5 (Conv1D) (None, 233, 128) 82048 concatenate_1[0][0]
__________________________________________________________________________________________________
conv1d_11 (Conv1D) (None, 233, 128) 82048 concatenate_2[0][0]
__________________________________________________________________________________________________
max_pooling1d_5 (MaxPooling1D) (None, 46, 128) 0 conv1d_5[0][0]
__________________________________________________________________________________________________
max_pooling1d_11 (MaxPooling1D) (None, 46, 128) 0 conv1d_11[0][0]
__________________________________________________________________________________________________
conv1d_6 (Conv1D) (None, 42, 128) 82048 max_pooling1d_5[0][0]
__________________________________________________________________________________________________
conv1d_12 (Conv1D) (None, 42, 128) 82048 max_pooling1d_11[0][0]
__________________________________________________________________________________________________
max_pooling1d_6 (MaxPooling1D) (None, 2, 128) 0 conv1d_6[0][0]
__________________________________________________________________________________________________
max_pooling1d_12 (MaxPooling1D) (None, 2, 128) 0 conv1d_12[0][0]
__________________________________________________________________________________________________
flatten_1 (Flatten) (None, 256) 0 max_pooling1d_6[0][0]
__________________________________________________________________________________________________
flatten_2 (Flatten) (None, 256) 0 max_pooling1d_12[0][0]
__________________________________________________________________________________________________
concatenate_3 (Concatenate) (None, 512) 0 flatten_1[0][0]
flatten_2[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 128) 65664 concatenate_3[0][0]
__________________________________________________________________________________________________
final_output (Dense) (None, 3) 387 dense_1[0][0]
==================================================================================================
Total params: 4,998,267
Trainable params: 4,998,267
Non-trainable params: 0
__________________________________________________________________________________________________

调用模型拟合为:

model.fit({'input_11':X_t, 'input_22':X_t}, y, batch_size=32, epochs=1, validation_data=(X_test, y_test))

我想为我提到的两个输入(input_11和input_22)提供相同的输入值,因此对两者使用相同的变量。上述所有变量的维度如下:

X_t: (66234, 300)
y: (66234, 3)
X_test: (2960, 300)
y_test: (2960, 3)

调用model.fit后出现以下错误:

Error when checking model input: 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: [array([[    0,     0,     0, ..., 19396,  9498, 21369],
[ 0, 0, 0, ..., 19688, 19396, 6742],
[ 0, 0, 0, ..., 21121, 20955, 1020],
...,
[ 0, ...

我该如何解决这个问题?谢谢

最佳答案

您可以将列表传递给模型的拟合方法以进行输入。

model.fit([X_t, X_t], y, batch_size=32, epochs=1, validation_data=(X_test, y_test))

编辑

您还应该传递两个数组作为验证数据。

model.fit([X_t, X_t], y, batch_size=32, epochs=1, validation_data=([X_test, X_test], y_test))

以下也可以工作。

model.fit({'input_11':X_t, 'input_22':X_t}, y, batch_size=32, epochs=1, validation_data=({'input_11':X_test, 'input_22':X_test}, y_test))

关于python - CNN 多输入,检查模型输入 : Expected to see 2 array(s), 时出错,但得到以下 1 个数组列表:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54742088/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com