首页 > 解决方案 > 将多维 NumPy 数组与列表传递给 fit() 会引发错误

问题描述

我正在试验 w/conv 层。我想输入两个 192x192x3 的图像,将它们连接起来,然后做一些其他的事情。模型摘要如下所示:

__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
input_40 (InputLayer)           (None, 192, 192, 3)  0                                            
__________________________________________________________________________________________________
input_41 (InputLayer)           (None, 192, 192, 3)  0                                            
__________________________________________________________________________________________________
concatenate_7 (Concatenate)     (None, 192, 192, 6)  0           input_40[0][0]                   
                                                                 input_41[0][0]      

我的shape两个输入看起来像这样:(1, 192, 192, 3)

如果我将 a 传递list()给该fit()方法,它可以正常工作,即:model.fit([input1, input2], ...)它可以正常工作。但是,如果我首先转换为 NumPy 数组:np_array = np.asarray([input1, input2])形状(2, 1, 192, 192, 3)为该fit()方法时会出现此错误:

ValueError: 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([[[[[1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.],
          ...,
          [1., 1., 1.],
          [1., 1., 1.],
          [1., 1., 1.]],

         [[1., 1., 1.],
          [1.,...

有任何想法吗?

标签: tensorflowmachine-learningkerasdeep-learning

解决方案


将数据传递给多个输入时,它应该是数组列表而不是一个大数组。有什么理由需要将它作为数组传递吗?


推荐阅读