keras-team/keras · error · ValueError
Axis is greater than the maximum allowed value
Error message
Axis {} is greater than the maximum allowed value: {} What it means
Consistency check in InputSpec.__init__ after the axes dict is parsed: with axes defined and ndim or max_ndim also given, every axis key must fit within the allowed rank; a key exceeding the computed max_dim indexes a dimension the input cannot have, so the spec is rejected.
Solutions
- Use negative indexing (e.g. -1 for the last axis) instead of a large positive index
- Raise ndim/max_ndim to accommodate the axis, or drop the axis entry from `axes`
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/input_spec.py:90 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/068cccc06ef92eb8.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/input_spec.py:90
self.max_ndim = max_ndim
self.min_ndim = min_ndim
self.name = name
self.optional = optional
self.allow_last_axis_squeeze = allow_last_axis_squeeze
try:
axes = axes or {}
self.axes = {int(k): axes[k] for k in axes}
except (ValueError, TypeError):
raise TypeError(
"Argument `axes` must be a dict with integer keys. "
f"Received: axes={axes}"
)
if self.axes and (self.ndim is not None or self.max_ndim is not None):
max_dim = (self.ndim if self.ndim else self.max_ndim) - 1
max_axis = max(self.axes)
if max_axis > max_dim:
raise ValueError(
"Axis {} is greater than the maximum "
"allowed value: {}".format(max_axis, max_dim)
)
def __repr__(self):
spec = [
(f"dtype={str(self.dtype)}") if self.dtype else "",
(f"shape={str(self.shape)}") if self.shape else "",
(f"ndim={str(self.ndim)}") if self.ndim else "",
(f"max_ndim={str(self.max_ndim)}") if self.max_ndim else "",
(f"min_ndim={str(self.min_ndim)}") if self.min_ndim else "",
(f"axes={str(self.axes)}") if self.axes else "",
]
return f"InputSpec({', '.join(x for x in spec if x)})"
def get_config(self):
return {
"dtype": self.dtype,View on GitHub (pinned to 7a34a03db6)