2017-07-25 4 views
2

Das Eingangselement besteht aus 3 Reihen mit jeweils 199 Spalten und der Ausgang hat 46 Zeilen und 1 SpalteKeras Mehr Abmessungen eingegeben simpleRNN: dimension Mismatch

Input.shape, output.shape 
((204563, 3, 199), (204563, 46, 1)) 

Wenn die Eingabe die folgenden Fehler gegeben wird ausgelöst wird:

from keras.layers import Dense 
from keras.models import Sequential 
from keras.layers.recurrent import SimpleRNN 

model = Sequential() 
model.add(SimpleRNN(100, input_shape = (Input.shape[1], Input.shape[2]))) 
model.add(Dense(output.shape[1], activation = 'softmax')) 
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy']) 
model.fit(Input, output, epochs = 20, batch_size = 200) 

Fehler ausgelöst:

Epoch 1/20 

--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-134-378dd431cf45> in <module>() 
     3 model.add(Dense(y_target.shape[1], activation = 'softmax')) 
     4 model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy']) 
----> 5 model.fit(X_input, y_target, epochs = 20, batch_size = 200) 
. 
. 
. 
ValueError: Error when checking model target: expected dense_6 to have 2 dimensions, but got array with shape (204563, 46, 1) 

Bitte legen Sie den Grund für das Problem und mögliche soution

Antwort

2

Das Problem ist, dass SimpleRNN(100) einen Tensor der Form zurückkehrt (204563, 100) damit die Dense(46) (seit output.shape[1]=46) einen Tensor (204563, 46) Form zurück, aber Ihre y_target haben Form (204563, 46, 1). Sie müssen die letzte Bemaßung beispielsweise mit y_target = np.squeeze(y_target) entfernen, damit die Bemaßung konsistent ist