{"record":{"id":"913ead2db94d444f","repo":"keras-team/keras","slug":"argument-axes-must-be-a-dict-with-integer-keys","errorCode":null,"errorMessage":"Argument `axes` must be a dict with integer keys. Received: axes={axes}","messagePattern":"Argument `axes` must be a dict with integer keys\\. Received: axes=(.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/input_spec.py","lineNumber":81,"sourceCode":"        self.dtype = (\n            backend.standardize_dtype(dtype) if dtype is not None else None\n        )\n        if shape is not None:\n            self.shape = backend.standardize_shape(shape)\n            self.ndim = len(shape)\n        else:\n            self.ndim = ndim\n            self.shape = None\n        self.max_ndim = max_ndim\n        self.min_ndim = min_ndim\n        self.name = name\n        self.optional = optional\n        self.allow_last_axis_squeeze = allow_last_axis_squeeze\n        try:\n            axes = axes or {}\n            self.axes = {int(k): axes[k] for k in axes}\n        except (ValueError, TypeError):\n            raise TypeError(\n                \"Argument `axes` must be a dict with integer keys. \"\n                f\"Received: axes={axes}\"\n            )\n\n        if self.axes and (self.ndim is not None or self.max_ndim is not None):\n            max_dim = (self.ndim if self.ndim else self.max_ndim) - 1\n            max_axis = max(self.axes)\n            if max_axis > max_dim:\n                raise ValueError(\n                    \"Axis {} is greater than the maximum \"\n                    \"allowed value: {}\".format(max_axis, max_dim)\n                )\n\n    def __repr__(self):\n        spec = [\n            (f\"dtype={str(self.dtype)}\") if self.dtype else \"\",\n            (f\"shape={str(self.shape)}\") if self.shape else \"\",\n            (f\"ndim={str(self.ndim)}\") if self.ndim else \"\",","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/input_spec.py#L63-L99","documentation":"Type guard in InputSpec.__init__: the `axes` argument must be a dict whose keys are (or convert to) integers, since they index tensor axes. If any key fails int() conversion a ValueError/TypeError is caught and re-raised as this TypeError, echoing the offending dict.","triggerScenarios":"Thrown at keras/src/layers/input_spec.py:81 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use integer axis keys, e.g. axes={-1: 10} or axes={1: 128}","Quote keys only if your framework normalizes them back to ints; otherwise remove quotes from config files","Pass axes=None when no per-axis constraints are needed"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}