-
Notifications
You must be signed in to change notification settings - Fork 19.4k
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
Easy way to combine CNN + LSTM? (e.g. LRCN network) #401
Comments
@anayebi read the documentation on the built in reshape layer. That should give you everything you need. Don't flatten the CNN outputs, use reshape instead. |
Add these two methods to Sequential object: def Conv2LSTM(self, num_filters, input_width): def LSTM2ConvLayer(self): Add this class to layers: class Permute(Layer):
|
Hi, n_hidden = 256 model = Sequential() |
Hi Afsaneh, In order to have the CNN layers to interact with the LSTM layer, they need to be distributed across time. I have made time distributed versions of Convolution2D, MaxPooling2D, and Flatten so that they can work with the LSTM layer. They can be found on my Github repo here: https://github.com/anayebi/keras-extra So, as an example, you could do what you propose above as follows (untested code): from keras.layers.extra import TimeDistributedConvolution2D, TimeDistributedMaxPooling2D, TimeDistributedFlatten n_hidden = 256 model = Sequential() |
@anayebi some bug here. In theano_backend.p |
Hi, |
Hello there, I get this error: when I use this architecture: model = Sequential() Am I using the package wrong? Or is there something I need to implement somewhere? Thanks for taking the time to read this |
@AntreasAntoniou Yes, the package expects an input that is 5D: (num_samples, num_timesteps, channels, rows, cols). Your input is missing the extra num_timesteps dimension. If you experience any more issues, feel free to post to the issues page on my repo: https://github.com/anayebi/keras-extra @OnlySang @afsanehghasemi At the moment, these layers don't work with the current version of Keras (which uses multiple backends). The errors you point out have to do with theano_backend.py, which does not allow input dimensions larger than 4. If you use a version of Keras from September or October (before the new update), then the layers as they currently are should work. On the other hand, if you don't want to use a slightly earlier Keras version, I am planning on releasing an updated version of the layers soon that should work with the newest Keras version. I will update this thread when I do release the update. |
Yes, I did realise that, I changed the input to (30, 1, 256, 256). Thanks for your prompt support here. I will be waiting for your update. |
I have pushed an updated version of my code that works with the newest @fchollet On a related note, could these layers be considered for inclusion It's somewhat impractical to keep up with the changes in Keras as a It could be best to put all the time distributed layers in one place, to be On Tuesday, December 22, 2015, afsanehghasemi notifications@github.com
|
Thanks so much man. I will go try it out now. |
Hello, I am using "keras-extra" in order to have CNN layers to interact with the LSTM layer. But when I run the code this error occurs "TypeError: rnn() got an unexpected keyword argument 'mask' ". Would you please help me on this issue? |
@Shadi94 Could you build a github gist with your code? |
#1623 provides a Convolutional3D layer in order to consider the time series as a dimension. I guess this combination of CNN+LSTM can be directly implemented by stacking LSTM layer on top of CNN. |
Hi @afsanehghasemi , Were you able to solve the issue? If yes, can you explain? |
@Shadi94 I also have the same errors: "TypeError: rnn() got an unexpected keyword argument 'mask' ", would you please update your fix? Thanks very much |
i've got a similar task.. and i think they develops a layer called permute or reshape to help with.. but is there some sample codes? @afsanehghasemi have you figure it out? thanks |
Is there possibility to use stateful in lstm? |
Hi, I am trying to work with CNN+LSTM and facing problem in using LSTM after CNN. From the last ConvLayer of the network i am getting the shape 32x8x26, how can i use LSTM after this? Thanks. |
@anirudhgupta22 |
I recently opened a new issue about it (See: Here 8268) but without an answer. Is it the same that you want? |
@anayebi hello i followed #4172 #421 and tries every possible way to integrate CNN (VGG16) with LSTM in keras, but i am continuously getting error below is my code
i am getting error that (here 5 is time step, 224,224 is image dimension and 3 is channel ) but when i supply samples also |
@usmanatif I also ran into this error, and can’t figure out ways to feed data into cnn+LSTM by generator. Did you solve this problem? |
@usmanatif @HTLife Did you try to permute the input dimensions to (1, 3, 224, 224, 5)? |
|
have u solved the issue of supplying the input using keras image generator? how u solved your problem? Any help would be appreciated |
in my methode, but i don't know this best method or not
|
I was wondering if there was a straightforward way in Keras (or would I have to write my own layer?) to combine a convolutional network which extracts features and then feeds it to an LSTM (or GRU, MUT1, etc) network (similar to Figure 1 of this paper: http://arxiv.org/pdf/1411.4389v3.pdf)?
Specifically, I want the input i_t to the convolutional network at a given timestep t to consist of n frames (in the case of Figure 1, n = 1), so i_t would be of dimension (num_rows, num_cols, n), from which the features of i_t are extracted and fed into an LSTM network, which produces a prediction y_t and a hidden state h_t. Then the next input i_{t+1} of dimension (num_rows, num_cols, n) is fed into the same convolutional network which outputs the features of i_{t+1} to the LSTM layer at timestep t+1, and h_t is fed to the LSTM layer at timestep t+1 from the LSTM layer at timestep t, from which the prediction y_{t+1} and hidden state h_{t+1} are produced, and so on.
I'm aware of #129; however, in this case, I believe the original poster wanted it so that the convolutional layer does not accept new inputs across timesteps (so something like Figure 3, pg. 4 of this paper: http://arxiv.org/pdf/1411.4555v2.pdf), which is not what I want.
Thanks in advance!
The text was updated successfully, but these errors were encountered: