CNN多输入,检查模型输入时出错:预计会看到2个数组,而是得到以下1个数组的列表:

问题描述 投票:1回答:1

我想将多个输入传递给我的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,     ...

我怎样才能解决这个问题?谢谢

python tensorflow keras conv-neural-network
1个回答
1
投票

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

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))
© www.soinside.com 2019 - 2024. All rights reserved.