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

How to implement CNN+LSTM using cudnn torch #388

Open
Kevinpsk opened this issue Dec 6, 2017 · 0 comments
Open

How to implement CNN+LSTM using cudnn torch #388

Kevinpsk opened this issue Dec 6, 2017 · 0 comments

Comments

@Kevinpsk
Copy link

Kevinpsk commented Dec 6, 2017

Hi guys,

I want to implement a CNN+LSTM model using cudnn torch for a sequence classification problem, but it seems I can not find the correct way to connect CNN with LSTM so that I can train with sequences. So I would really appreciate it if you can help me. My sequential data is 2D with dimension something like this: 500 * 100 * 3 * 20 * 9 (SeqLen * NumSeq * NumPlane * Height * Width), and my targets are like this 500 * 100 * 1 (SeqLen * NumSeq * TargetDim). So in this particular case, I have 100 sequences, each with 500 time steps. My features are 2D images with 3 channels and my targets are just 1D labels.

I build my model like this,

features = features:view(50000, 3, 20, 9) -- I reshape the feature to be able to feed into CNN
model = nn.Sequential()
model:add(cudnn.SpatialConvolution(3, 10, 9, 9, 1, 1))
model:add(cudnn.ReLU())
model:add(cudnn.SpatialMaxPooling(1, 2, 1, 2)) -- after pooling output size is at each time step is 60
model:add(nn.View(500, 100, 60)) -- I reshape the outputs from CNN to SeqLen * NumSeq * FeatSize
model:add(cudnn.LSTM(20, 20)) -- first LSTM layer
model:add(cudnn.LSTM(20, 20)) -- second LSTM layer
model:add(nn.Sequencer(nn.Linear(20, 1)))
model:add(nn.Sequencer(nn.Sigmoid())) -- finally get a scalar output

After I build this model, the forward path works fine, but the backward path breaks with the following error,

cudnnConvolutionBackwardFilter failed: 9 convDesc=[mode : CUDNN_CROSS_CORRELATION datatype : CUDNN_DATA_FLOAT]

So what could be wrong with my code then? Or more generally, how to build CNN+LSTM model in using cudnn torch? Thanks a lot for your help,

Kevin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant