keras-team/keras · error · ValueError

The channel dimension of the inputs (last axis) should be…

Error message

The channel dimension of the inputs (last axis) should be defined. Found None. Full input shape received: input_shape={inputs_shape}

What it means

Raised by ConvLSTM.build when the channel axis of the input (last axis for channels_last, axis 1 for channels_first) is None. Without a known channel count the layer cannot size its kernel, so it rejects the shape at build time.

Solutions

  1. Define the channel dimension in the input shape, e.g. Input(shape=(timesteps, h, w, 3))
  2. Ensure an upstream layer does not produce an undefined channel axis (e.g. operations that collapse the last dim dynamically)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/layers/rnn/conv_lstm.py:178 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/7d7eceeecb052fb4. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/rnn/conv_lstm.py:178

        self.dropout_mask_count = 4
        self.input_spec = InputSpec(ndim=rank + 2)
        self.state_size = -1  # Custom, defined in methods

    def build(self, inputs_shape, states_shape=None):
        if self.data_format == "channels_first":
            channel_axis = 1
            self.spatial_dims = inputs_shape[2:]
        else:
            channel_axis = -1
            self.spatial_dims = inputs_shape[1:-1]
        if None in self.spatial_dims:
            raise ValueError(
                "ConvLSTM layers only support static "
                "input shapes for the spatial dimension. "
                f"Received invalid input shape: input_shape={inputs_shape}"
            )
        if inputs_shape[channel_axis] is None:
            raise ValueError(
                "The channel dimension of the inputs (last axis) should be "
                "defined. Found None. Full input shape received: "
                f"input_shape={inputs_shape}"
            )
        self.input_spec = InputSpec(
            ndim=self.rank + 3, shape=(None,) + inputs_shape[1:]
        )

        input_dim = inputs_shape[channel_axis]
        self.input_dim = input_dim
        self.kernel_shape = self.kernel_size + (input_dim, self.filters * 4)
        recurrent_kernel_shape = self.kernel_size + (
            self.filters,
            self.filters * 4,
        )

        self.kernel = self.add_weight(
            shape=self.kernel_shape,

View on GitHub (pinned to 7a34a03db6)