2017-06-16 78 views
3

我想多類分類,這裏是我的訓練輸入的細節和輸出:ValueError異常:輸入0與層lstm_13不相容:預計NDIM = 3,發現NDIM = 4

train_input.shape= (1, 95000, 360) (95000 length input array with each element being an array of 360 length)

train_output.shape = (1, 95000, 22) (22 Classes are there)

model = Sequential() 

model.add(LSTM(22, input_shape=(1, 95000,360))) 
model.add(Dense(22, activation='softmax')) 
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) 
print(model.summary()) 
model.fit(train_input, train_output, epochs=2, batch_size=500) 

錯誤是:

ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 in line: model.add(LSTM(22, input_shape=(1, 95000,360)))

請幫我,我不能夠通過其他的答案來解決這個問題。

回答

3

我通過使

input size: (95000,360,1) and output size: (95000,22)

解決了這個問題,並改變了輸入外形在代碼(360,1)其中模型定義:

model = Sequential() 
model.add(LSTM(22, input_shape=(360,1))) 
model.add(Dense(22, activation='softmax')) 
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) 
print(model.summary()) 
model.fit(ml2_train_input, ml2_train_output_enc, epochs=2, batch_size=500) 
0

input_shape應該是(timesteps,n_features)。刪除第一個維度。

input_shape = (95000,360) 

相同的輸出。

+0

不,也給一些錯誤,如預期是:無,95000,360但發現1,95000,360 –

+1

這是您的輸入數據形狀的問題。第一個維度應該是每個樣本。你的輸入應該是(n_samples,timesteps,n_features)。看看你的其他評論,95000是你的n_samples而不是你的時間步。如果你只有一個360時間步的功能,那麼你提出的是正確的格式。 – michetonu

+0

好吧,我的輸入有360-360個塊(我想將其視爲特徵),那麼輸入的形狀和應該寫在裏面的內容應該是什麼 - > {model.add(LSTM(22,input_shape =(?)))} –

相關問題