2016-11-13 47 views
0

我目前正在嘗試使線性迴歸網絡能夠將我的輸入數據映射到所需的輸出數據。爲什麼我不能訓練我的模型

我的輸入和輸出當前存儲爲以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.2, 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]])] 

那我做錯了嗎?爲什麼我無法將數據傳遞給模型?

+0

什麼是你的形狀中的'x'? 「輸入端的每個矩陣的尺寸[400,x] =>通過打印輸入[0]輸出。形狀 輸出端的每個矩陣的尺寸爲[13,x] =>輸出爲打印輸出[0] .shape「 – pyan

+0

x和y是numpy.ndarrays的列表.. –

回答

1

轉置輸入numpy數組。 Keras需要輸入數組的形狀爲(number_of_samples, number_of_features)

+0

so ... x.shape?或x [0] .shape? –

+0

Did you try it? – pyan

+0

因此,由於輸入是numpy.ndarrays的列表,我將無法輸出input.shape。 但我可以給輸入[0] .shape .. 哪個是:。 (400,288) 400的輸入功能和288號是本ndarray包含的樣本的數目 –