深度学习拟合错误(传递给模型的Numpy数组列表不是模型预期的大小.) [英] Deep Learning fit error (the list of Numpy arrays that you are passing to your model is not the size the model expected.)

查看:85
本文介绍了深度学习拟合错误(传递给模型的Numpy数组列表不是模型预期的大小.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是深度学习的新手.我正在尝试遵循 fast.ai 讲座系列,并尝试在Kaggle内核中手动复制工作.

I'm new to Deep Learning. I'm trying to follow along with the fast.ai lecture series, and trying to reproduce the work manually in a Kaggle kernel.

我正在尝试通过Kaggle的猫对狗Redux进行研究.我不关心准确性,我只是想让事情起作用.

I'm trying to work through cats vs. dogs Redux in Kaggle. I'm not concerned with accuracy, I just want to get something working.

我使用的是Keras和VGG16模型,如fast.ai课程所述.我也依赖于这篇文章可以帮助我起步.

I'm using Keras and the VGG16 model, as outlined in the fast.ai course. I'm also leaning on code outlined in this article to get me off the ground.

这是我的Kaggle笔记本.

在尝试拟合我不知道如何解释的模型时遇到错误:

I'm encountering an error when trying to fit my model that I don't know how to interpret:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-26-596f25281fc2> in <module>()
     12 #model.fit(input[0].transpose(), output[0].transpose())
     13 
---> 14 model.fit(X, Y, epochs=100, batch_size=6000, verbose=1)

/opt/conda/lib/python3.6/site-packages/Keras-2.1.2-py3.6.egg/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
   1591             class_weight=class_weight,
   1592             check_batch_axis=False,
-> 1593             batch_size=batch_size)
   1594         # Prepare validation data.
   1595         do_validation = False

/opt/conda/lib/python3.6/site-packages/Keras-2.1.2-py3.6.egg/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_batch_axis, batch_size)
   1428                                     output_shapes,
   1429                                     check_batch_axis=False,
-> 1430                                     exception_prefix='target')
   1431         sample_weights = _standardize_sample_weights(sample_weight,
   1432                                                      self._feed_output_names)

/opt/conda/lib/python3.6/site-packages/Keras-2.1.2-py3.6.egg/keras/engine/training.py in _standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
     81                 'Expected to see ' + str(len(names)) + ' array(s), '
     82                 'but instead got the following list of ' +
---> 83                 str(len(data)) + ' arrays: ' + str(data)[:200] + '...')
     84         elif len(names) > 1:
     85             raise ValueError(

ValueError: 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 1 array(s), but instead got the following list of 24500 arrays: [array([[1],
       [0]]), array([[1],
       [0]]), array([[0],
       [1]]), array([[1],
       [0]]), array([[1],
       [0]]), array([[1],
       [0]]), array([[1],
       [0]]), array([[0],
     ...

这里有更多信息:

X = np.array([i[0] for i in train]).reshape(-1,IMG_SIZE,IMG_SIZE,3)
Y = [i[1] for i in train]

> type(X)
numpy.ndarray

> X.shape
(24500, 50, 50, 3)

> type(Y)
list

> len(Y)
24500

> Y[0]
[1 0]

> model.summary()
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_7 (InputLayer)         (None, 50, 50, 3)         0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 50, 50, 64)        1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 50, 50, 64)        36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 25, 25, 64)        0         
_________________________________________________________________
block2_conv1 (Conv2D)        (None, 25, 25, 128)       73856     
_________________________________________________________________
block2_conv2 (Conv2D)        (None, 25, 25, 128)       147584    
_________________________________________________________________
block2_pool (MaxPooling2D)   (None, 12, 12, 128)       0         
_________________________________________________________________
block3_conv1 (Conv2D)        (None, 12, 12, 256)       295168    
_________________________________________________________________
block3_conv2 (Conv2D)        (None, 12, 12, 256)       590080    
_________________________________________________________________
block3_conv3 (Conv2D)        (None, 12, 12, 256)       590080    
_________________________________________________________________
block3_pool (MaxPooling2D)   (None, 6, 6, 256)         0         
_________________________________________________________________
block4_conv1 (Conv2D)        (None, 6, 6, 512)         1180160   
_________________________________________________________________
block4_conv2 (Conv2D)        (None, 6, 6, 512)         2359808   
_________________________________________________________________
block4_conv3 (Conv2D)        (None, 6, 6, 512)         2359808   
_________________________________________________________________
block4_pool (MaxPooling2D)   (None, 3, 3, 512)         0         
_________________________________________________________________
block5_conv1 (Conv2D)        (None, 3, 3, 512)         2359808   
_________________________________________________________________
block5_conv2 (Conv2D)        (None, 3, 3, 512)         2359808   
_________________________________________________________________
block5_conv3 (Conv2D)        (None, 3, 3, 512)         2359808   
_________________________________________________________________
block5_pool (MaxPooling2D)   (None, 1, 1, 512)         0         
=================================================================
Total params: 14,714,688
Trainable params: 14,714,688
Non-trainable params: 0
_________________________________________________________________

和模型:

model = VGG16(weights='imagenet', include_top=False, input_shape=(img_rows, img_cols, img_channel))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X, Y, epochs=100, batch_size=6000, verbose=1)

我已经在Google周围搜索,但是我对如何解释这一点感到迷惑.这个 SO问题似乎很相似,并且似乎表明输出是问题所在,但我不确定在这里如何应用.

I've googled around but I'm at a loss for how to interpret this. This SO question seems similar, and seems to indicate that the output is the problem, but I'm not sure how that would apply to me here.

推荐答案

您应该简单地将Y转换为形状为(24500,2)的numpy数组:

You should simply transform your Y to a numpy array with shape (24500, 2):

Y = np.ndarray(Y)

这篇关于深度学习拟合错误(传递给模型的Numpy数组列表不是模型预期的大小.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆