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

Why can't i train my model

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

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

回归网络的输入维度是 400 回归网络的输出维度为 13。

输入端的每个矩阵都有维度 [400,x] => 通过 print input[0].shape

输出

输出端的每个矩阵都有维度 [13,x] => 通过 print output[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 array of training data, or list of Numpy arrays if the model has multiple inputs. If all inputs in the model are named, you can also pass a dictionary mapping input names to Numpy arrays.

y: Numpy array of target data, or list of Numpy arrays if the model has multiple outputs. If all outputs in the model are named, you can also pass a dictionary mapping output names to Numpy arrays.

我有一个 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]])]

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

转置您的输入 numpy 数组。 Keras 要求输入数组的形状为 (number_of_samples, number_of_features).