LSTM on EEG data using Keras

228 views
Skip to first unread message

rakiba...@gmail.com

unread,
Sep 8, 2018, 12:49:06 PM9/8/18
to Keras-users
I am working with EEG data. I want to use the window approach on row signal. My train data size is (1000, 50, 100, 32). 

Where,

1000= sample size/ trial number 
50= number of the window in each trial 
100= sample of time series signal  
32= number of channel.

I want to run LSTM on that signal. Please see the sample code

    from sklearn.model_selection import train_test_split
    import numpy as np
    seed = 7
    np.random.seed(seed)
    X=np.random.rand(1000, 50, 100, 32)
    y=np.random.rand(1000)

    X_train, X_test, y_train, y_test = train_test_split(X, 
    y, test_size=0.33, random_state=seed)
    
    from keras.models import Sequential
    from keras.layers import Dense
    from keras.layers import LSTM
    from keras.layers import Dropout
    model = Sequential()
    model.add(LSTM(50, return_sequences=False, 
    activation='relu',batch_size=5, input_shape=(5,10, 32)))
    model.add(Dropout(0.2))
    model.add(Dense(1, activation='sigmoid'))
    
    model.compile(loss='mae', optimizer='adam')
    print(model.summary())
    history=model.fit(X_train, y_train, validation_data 
    (X_test,y_test), epochs=3, batch_size=10)

I can not run the code. Can you please help me?

Ted Yu

unread,
Sep 8, 2018, 1:22:22 PM9/8/18
to rakiba...@gmail.com, keras...@googlegroups.com
With the following change (note the change to input_shape), 

model.add(LSTM(50, return_sequences=True,
  activation='relu',batch_size=5, input_shape=(10, 32)))

I got:
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
lstm_1 (LSTM)                (5, 10, 50)               16600
_________________________________________________________________
dropout_1 (Dropout)          (5, 10, 50)               0
_________________________________________________________________
dense_1 (Dense)              (5, 10, 1)                51
=================================================================
Total params: 16,651
Trainable params: 16,651
Non-trainable params: 0

--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/d4967f00-4eb2-4c0d-b376-bde84ce37657%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rakiba...@gmail.com

unread,
Sep 8, 2018, 1:37:11 PM9/8/18
to Keras-users
but, if I want to run it. it gives me value error: "Error when checking input: expected lstm_57_input to have 3 dimensions, but got array with shape (670, 50, 100, 32) "
Can you help me to fix the model.fit part

Thanks

Sergey O.

unread,
Sep 8, 2018, 2:40:29 PM9/8/18
to rakiba...@gmail.com, Keras-users
The expected input is
(samples,time,channels)

Your descriptions are very vague:
1000= sample size/ trial number 
50= number of the window in each trial 
100= sample of time series signal  
32= number of channel.

Do you mean?
1000 = samples
50 = I'm guessing you are sliding a window of 50 across a time series???
100 = number of windows?
32 = channels



--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/371e9423-a327-4c95-bbc8-d850c384c122%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages