为什么我不能训练我的模型

时间:2016-11-13 20:42:51

标签: python arrays list numpy keras

我目前正在尝试建立一个能够将输入数据映射到所需输出数据的线性回归网络。

我的输入和输出当前存储为存储为numpy.ndarray的矩阵列表。

回归网络的输入维度为400 并且回归网络的输出维数是13.

输入侧的每个矩阵的尺寸为[400,x] =>通过打印输入[0] .shape输出

输出侧的每个矩阵具有尺寸[13,x] =>输出按打印输出[0] .shape

我目前定义的网络如下所示:

print "Training!"
model = Sequential()
model.add(Dense(output_dim=13, input_dim=400, init="normal"))
model.add(Activation("relu"))
print "Compiling"
model.compile(loss='mean_squared_error', optimizer='sgd')
model.fit(input,output,verbose=1)

这里的问题是在火车阶段。

它在某种程度上需要很长时间,并且没有提供有关进展的信息。似乎系统停止,并以此错误消息终止。

Traceback (most recent call last):
  File "tensorflow_datapreprocess_mfcc_extraction_rnn.py", line 169, in <module>
    model.fit(train_set_data,train_set_output,verbose=1)
  File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 620, in fit
    sample_weight=sample_weight)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 1034, in fit
    batch_size=batch_size)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 961, in _standardize_user_data
    exception_prefix='model input')
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 51, in standardize_input_data
    '...')
Exception: 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 1 arrays but instead got the following list of 270 arrays: [array([[ -1.52587891e-04,   3.05175781e-05,  -1.52587891e-04,
         -5.18798828e-04,   3.05175781e-05,  -3.96728516e-04,
          1.52587891e-04,   3.35693359e-04,  -9.15527344e-05,
          3.3...

我猜这个错误可能是我解析输入数据的方式,这对我来说是黑魔法。文档说明了

https://keras.io/models/model/

fit(self, x, y, batch_size=32, nb_epoch=10, verbose=1, callbacks=[], validation_split=0.0, validation_data=None, shuffle=True, class_weight=None, sample_weight=None)
  

x:训练数据的Numpy数组,或模型中的Numpy数组列表   有多个输入。如果模型中的所有输入都已命名,则可以   还传递一个字典映射输入名称到Numpy数组。

     

y:Numpy目标数据数组,或Numpy数组列表(如果是模型)   有多个输出。如果模型中的所有输出都已命名,则可以   还传递一个字典映射输出名称到Numpy数组。

我有一个Numpy数组列表?怎么知道它是必须读入的行?...我不知道。 我想numpy.ndarrays存储为numpy.arrays列表,其中每个数组都是一行。?

根据这个简单的例子,似乎如此:

输入:

import numpy as np

lis = []
output_data = np.random.rand(5,3)
output_data_1 = np.random.rand(5,2)
lis.append(output_data)
lis.append(output_data_1)
print output_data.shape
print output_data_1.shape
print lis

输出:

(5, 3)
(5, 2)
[array([[ 0.15509364,  0.20140267,  0.13678847],
       [ 0.27932102,  0.38430659,  0.87265863],
       [ 0.01053336,  0.28403731,  0.19749507],
       [ 0.95775409,  0.96032907,  0.46996195],
       [ 0.29515174,  0.74466708,  0.78720968]]), array([[ 0.34216058,  0.74972468],
       [ 0.97262113,  0.84451951],
       [ 0.72230052,  0.30852572],
       [ 0.47586734,  0.03382701],
       [ 0.37998285,  0.80772875]])]

那么我做错了什么?为什么我不能将数据传递给模型?

1 个答案:

答案 0 :(得分:1)

转置输入numpy数组。 Keras要求输入数组的形状为f

相关问题