1
$\begingroup$

My x_train shape is (798,3) and y_train input shape is (798, 1). I am creating a RNN like this

def create_rnn_model():
    model = Sequential()
    model.add(SimpleRNN(20,return_sequences=False,stateful=stateful,activation='relu',batch_input_shape=(1,3,1)))
    model.add(Activation('relu'))
    adam = optimizers.Adam(lr=0.001)
    model.compile(loss='mean_squared_error', optimizer=adam, metrics=[root_mean_squared_error])

    return model

But this returns the error

ValueError: Error when checking input: expected simple_rnn_1_input to have 3 dimensions, but got array with shape (798, 3)

My batch size =1 and my timestep is 3 and dat_dim=1 .Then where am I doing it wrong? Any help is appreciated.

EDIT

I changed my x_train to shape (798,3,1) and y_train shape to (798,) and ran the model but it threw an error

ValueError: Error when checking target: expected activation_1 to have shape (20,) but got array with shape (1,)

But I can run the model with 1 unit. How do I specify the model to run with 20 units instead of one.

$\endgroup$
  • 1
    $\begingroup$ We don't even know what library you are using (and I assume this is python). I think you should provide a working code sample, and ask on stackoverflow (this is a programming question obviously). $\endgroup$ – Robin Oct 23 '18 at 11:48
  • $\begingroup$ Rather than a programming question my real question is whether am I correct feeding the input or how wrong I am from the model perspective $\endgroup$ – Ricky Oct 24 '18 at 4:32
  • $\begingroup$ possible duplicate:-datascience.stackexchange.com/questions/32858/… $\endgroup$ – naive Oct 24 '18 at 5:13
1
$\begingroup$

First for RNN part, you should consider to read documentation about input_shape and batch_input_shape.

Then your Activation layer seems to be useless because you already apply relu activation in RNN layer.

Finally, your network returns output's shape of (20,) (RNN return (20,) and activation don't change shape) and you compare this with y_train with shape of (1,). Shapes dismatch so it return this error

EDIT: You can print model.summary() to monitor input/output 's shape

$\endgroup$
0
$\begingroup$

So from research I found out that for a RNN te input has to be in 3D format so I need to reshape by 2D data to 3D data . Then you need to specify the batch size,timestep and data_dim of your data .Hope it helps anyone .

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.