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

Demo or example code #5

Closed
jamesmf opened this issue Feb 8, 2016 · 5 comments
Closed

Demo or example code #5

jamesmf opened this issue Feb 8, 2016 · 5 comments

Comments

@jamesmf
Copy link

jamesmf commented Feb 8, 2016

Is there example code anywhere? This is an exciting addition to keras, and I'd love to see it in action. I attempted to adapt your 'untested' code snippet from

keras-team/keras#401

but had trouble going from the TimeDistributedFlatten to the LSTM layers.

model = Sequential()
model.add(TimeDistributedConvolution2D(8, 4, 4, border_mode='same', input_shape=(n_timesteps,1, 28, 28)))
model.add(TimeDistributedMaxPooling2D(pool_size=(2, 2)))
model.add(Activation('relu'))
model.add(TimeDistributedFlatten())
model.add(LSTM(256, return_sequences=False))
model.add(Dense(nb_classes))
model.add(Activation('softmax')

That yields the following dimension mismatch:
Inputs shapes: [(32, 392), (1568, 256)]

My test case is simply processing windows within MNIST images sequentially. My window size is (15,15) resulting in 196 windows.

The shape of X_train is (60000, 196, 1, 15, 15)

If I instead try return_sequences = True in the RNN layer, I get
AssertionError: Incompatible shapes: layer expected input with ndim=2 but previous layer has output_shape (None, 196, 256)

Is there an example anywhere that I could use to troubleshoot?

Thanks

@jamesmf
Copy link
Author

jamesmf commented Feb 8, 2016

Okay I already see at least one thing wrong here.

I was imagining hooking up the last time-step's output from the RNN to a vanilla Dense network. Does that make sense? Or does this implementation depend on the output vector having the same time dimension as the input?

@anayebi
Copy link
Owner

anayebi commented Feb 8, 2016

Yeah if return_sequences=False, then you do want a Dense network, not a TimeDistributedDense.

I think the issue is with your input_shape argument. You mention that X_train is of the shape (60000, 196, 1, 15, 15). If that's the case, then your input_shape to the first TimeDistributedConvolution2D layer should be input_shape=(196,1, 15, 15).

Also, as a sanity check what version of Keras are you using? I can only guarantee support for version 0.3.0 and lower.

@jamesmf
Copy link
Author

jamesmf commented Feb 9, 2016

Yep, I'm using 0.3.0.

Yeah the input shape was the issue - I was focused on the error and not really checking the code.

It seems to be working now. I'll post a link with the working code and then close the issue.

Thanks

@jamesmf
Copy link
Author

jamesmf commented Feb 9, 2016

https://github.com/jamesmf/mnistCRNN

Above is a working TimeDistributedConvolution Example. It takes a set of MNIST images and learns to predict their sum.

@jamesmf jamesmf closed this as completed Feb 9, 2016
@anayebi
Copy link
Owner

anayebi commented Feb 9, 2016

Great thanks! I added the link to your demo in the ReadMe :) 👍

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

2 participants