Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gcn_lstm layer: Stateful lstm layers #2078

Open
ajikmr opened this issue Jan 29, 2023 · 0 comments
Open

Gcn_lstm layer: Stateful lstm layers #2078

ajikmr opened this issue Jan 29, 2023 · 0 comments
Labels
enhancement New feature or request sg-library

Comments

@ajikmr
Copy link

ajikmr commented Jan 29, 2023

My time series prediction requires Stateful lstm layers. In gcn_lstm layer, currently it is not so.

I have tried to add 'stateful=True' in the gcn_lstm.py file. But this option requires that I also add batch input shape information. What would be appropriate way to add this parameter.

It will be great to also have a demo file for gcn_lstm with stateful lstm layers.

To make code work for stateful LSTM layers, I have created a class GCN_LSTM_STATEFUL which is a copy of GCN_LSTM class, except lstm layers are defined as below. I have hard-coded batch_input_shape for now to see it can run. Function call 'in_out_tensors()' throws error as shown further below.


    self._lstm_layers = [
        LSTM(layer_size, activation=activation, batch_input_shape=(1,6,5), stateful=True, return_sequences=True)
        for layer_size, activation in zip(
            self.lstm_layer_sizes[:-1], self.lstm_activations
        )
    ]
    self._lstm_layers.append(
        LSTM(
            self.lstm_layer_sizes[-1],
            activation=self.lstm_activations[-1],
            batch_input_shape=(1,6,200),
            stateful=True,
            return_sequences=False,
        )
    )

ERROR


ValueError Traceback (most recent call last)
/tmp/ipykernel_9509/572892708.py in
----> 1 x_input, x_output = gcn_lstm.in_out_tensors()

~/install/anaconda3/lib/python3.9/site-packages/stellargraph/layer/gcn_lstm.py in in_out_tensors(self)
636
637 x_inp = [x_t, out_indices_t]
--> 638 x_out = self(x_inp)
639
640 return x_inp[0], x_out

~/install/anaconda3/lib/python3.9/site-packages/stellargraph/layer/gcn_lstm.py in call(self, x)
604
605 for layer in self._lstm_layers:
--> 606 h_layer = layer(h_layer)
607
608 h_layer = Dropout(self.dropout)(h_layer)

~/install/anaconda3/lib/python3.9/site-packages/keras/layers/rnn/base_rnn.py in reset_states(self, states)
874 batch_size = spec_shape[1] if self.time_major else spec_shape[0]
875 if not batch_size:
--> 876 raise ValueError(
877 "If a RNN is stateful, it needs to know "
878 "its batch size. Specify the batch size "

ValueError: If a RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors:

  • If using a Sequential model, specify the batch size by passing a batch_input_shape argument to your first layer.
  • If using the functional API, specify the batch size by passing a batch_shape argument to your Input layer.
@ajikmr ajikmr added enhancement New feature or request sg-library labels Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sg-library
Projects
None yet
Development

No branches or pull requests

1 participant