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
How to stack convolutional layer and lstm? #129
Comments
The output of What's your input, and what are you actually trying to achieve? |
@fchollet I know what you say, So I have to add new layers to keras. When it's a convolutional nn, the input is (nb_samples, stack_size, rows, cols); when it's a recurrent nn, the input is (nb_sampels, max_length, features). I stack recurrent after convolution, so the input must be (nb_samples, max_length, stack_size, rows, cols). It's not easy to do this. I will do several reshape between layers. You can learn more about connectionist temporal classification. |
class MyReshape(Layer):
def get_output(self, train):
X = self.get_input(train)
nshape = (1,) + X.shape
return theano.tensor.reshape(X, nshape) It turns a batch of N vectors into a batch of size 1 containing a sequence of N vectors. Note that if you do something like that, the length of the input and of the labels won't match, so you won't be able to use the |
@fchollet what is the difference between the model.fit and the model.train that you reference above? |
@simonhughes22 it has been renamed |
Thanks |
@fchollet 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 |
I met this error too,have you solved it? |
@fchollet @chineseqsc @usmanatif |
I want to extract features through CNN and do squence labeling through LSTM? How could I stack these different layers together? And there would be problem when traning the stacked nn?
59 model = Sequential()
60 model.add(Convolution2D(20, 1, 7, 7, border_mode='full'))
61 model.add(Activation('relu'))
62 model.add(MaxPooling2D(poolsize=(2, 2)))
63 model.add(Convolution2D(50, 20, 5, 5, border_mode='full'))
64 model.add(Activation('relu'))
65 model.add(MaxPooling2D(poolsize=(2, 2)))
66 model.add(Convolution2D(100, 50, 3, 3, border_mode='full'))
67 model.add(Activation('relu'))
68 model.add(MaxPooling2D(poolsize=(2, 2)))
69 model.add(Flatten())
70 #model.add(Dense(100_6_6, 4096, init='normal'))
71 #model.add(Dropout(0.5))
72 model.add(LSTM(100_6_6, 512,return_sequences=True)) # try using a GRU instead, for fun
73 model.add(Dense(512, nb_classes, init='normal'))
74 model.add(Activation('softmax'))
75
76 # try using different optimizers and different optimizer configs
77 sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
78 model.compile(loss='categorical_crossentropy', optimizer=sgd, class_mode="categorical")
The text was updated successfully, but these errors were encountered: