Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python CNN多输入,检查模型输入时出错:预期会看到2个数组,但得到以下1个数组的列表:_Python_Tensorflow_Keras_Conv Neural Network - Fatal编程技术网

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

Python CNN多输入,检查模型输入时出错:预期会看到2个数组,但得到以下1个数组的列表:,python,tensorflow,keras,conv-neural-network,Python,Tensorflow,Keras,Conv Neural Network,我想将多个输入传递给我的CNN模型。遵循文档并传递2个值,但面临上述错误。 模型摘要: __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ========

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