question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ConvLSTM2D: return_sequences=False returns a 5D tensor (should return 4D)

See original GitHub issue

According to ConvLSTM2D documentation, when return_sequences=False, the ConvLSTM2D is supposed to only return the last element of the sequence. Specifically:

     # Output shape
        - if `return_sequences`
             - if data_format='channels_first'
                5D tensor with shape:
                `(samples, time, filters, output_row, output_col)`
             - if data_format='channels_last'
                5D tensor with shape:
                `(samples, time, output_row, output_col, filters)`
        - else
            - if data_format ='channels_first'
                4D tensor with shape:
                `(samples, filters, output_row, output_col)`
            - if data_format='channels_last'
                4D tensor with shape:
                `(samples, output_row, output_col, filters)`
            where o_row and o_col depend on the shape of the filter and
            the padding

But setting return_sequences=False seem to have no effect and the layer continues to return a 5-d tensor.

Is this a bug? Is there a workaround?

Here is my code:

def create_model(input_shape):

    num_filters = 15
    model = Sequential()
    model.add(ConvLSTM2D(filters=num_filters, kernel_size=(3, 3),
                         # input_shape=(None, 40, 40, 1),
                         input_shape=input_shape,
                         padding='same', return_sequences=True))
    model.add(BatchNormalization())

    model.add(ConvLSTM2D(filters=num_filters/2, kernel_size=(3, 3),
                         padding='same', return_sequences=True))
    model.add(BatchNormalization())

    model.add(ConvLSTM2D(filters=num_filters, kernel_size=(3, 3),
                         padding='same', return_sequences=False))
    model.add(BatchNormalization())

    model.add(Conv2D(filters=1, kernel_size=(3, 3),
                     activation='sigmoid',
                     padding='same', data_format='channels_last'))

    opt = optimizers.Adam(lr=1e-4)
    model.compile(loss='mae', optimizer=opt, metrics=[metrics.mae])

    return model

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sunmonkcommented, Jan 31, 2018

hey. seq.add(ConvLSTM2D(filters=40, kernel_size=(3, 3), padding=‘same’, data_format=‘channels_last’, return_sequences=False))

filters should not be 40 but 3!

seq.add(ConvLSTM2D(filters=3, kernel_size=(3, 3), padding=‘same’, data_format=‘channels_last’, return_sequences=False))

1reaction
fcholletcommented, Jun 20, 2017

Can’t reproduce, in this script, the output of the last ConvLSTM2D is a 4D tensor with shape (None, 40, 40, 40).

_standardize_input_data

It sounds like the problem is with the data that you are passing as input/target.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reshape a 4D Tensor output of a Convolutional Layer to 5D ...
Next I want to feed this output from the VGGnet into a ConvLSTM2D layer. But for this I hvae to convert it into...
Read more >
ConvLSTM2D layer - Keras
If return_sequences : 5D tensor with shape: (samples, timesteps, filters, new_rows, new_cols) if data_format='channels_first' or shape: (samples, timesteps, ...
Read more >
tf.keras.layers.ConvLSTM2D | TensorFlow
E.g. node_index=0 will correspond to the first time the layer was called. Returns: A tensor (or list of tensors if the layer has...
Read more >
What is ConvLSTM? - Kaggle
Call arguments: inputs: A 5D tensor. mask: Binary tensor of shape `(samples, timesteps)` indicating whether a given timestep should be masked. training: ...
Read more >
An introduction to ConvLSTM - Medium
The Convolution layer input is a set of images as a 4D tensor with shape ... then it returns a sequence as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found