{"record":{"id":"f4431c9ae2663c0e","repo":"keras-team/keras","slug":"axis-must-be-of-type-int-received-axis-axis","errorCode":null,"errorMessage":"`axis` must be of type `int`. Received: axis={axis} of type {type(axis)}","messagePattern":"`axis` must be of type `int`\\. Received: axis=(.+?) of type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/losses/losses.py","lineNumber":2180,"sourceCode":"            example, if `0.1`, use `0.1 / num_classes` for non-target labels\n            and `0.9 + 0.1 / num_classes` for target labels.\n        axis: Defaults to `-1`. The dimension along which the entropy is\n            computed.\n\n    Returns:\n        Categorical crossentropy loss value.\n\n    Example:\n\n    >>> y_true = [[0, 1, 0], [0, 0, 1]]\n    >>> y_pred = [[0.05, 0.95, 0], [0.1, 0.8, 0.1]]\n    >>> loss = keras.losses.categorical_crossentropy(y_true, y_pred)\n    >>> assert loss.shape == (2,)\n    >>> loss\n    array([0.0513, 2.303], dtype=float32)\n    \"\"\"\n    if isinstance(axis, bool):\n        raise ValueError(\n            \"`axis` must be of type `int`. \"\n            f\"Received: axis={axis} of type {type(axis)}\"\n        )\n    y_pred = ops.convert_to_tensor(y_pred)\n    y_true = ops.cast(y_true, y_pred.dtype)\n\n    if y_pred.shape is not None:\n        axis = canonicalize_axis(axis, len(y_pred.shape))\n        if y_pred.shape[axis] == 1:\n            warnings.warn(\n                \"In loss categorical_crossentropy, expected \"\n                \"y_pred.shape to be (batch_size, num_classes) \"\n                f\"with num_classes > 1. Received: y_pred.shape={y_pred.shape}. \"\n                \"Consider using 'binary_crossentropy' if you only \"\n                \"have 2 classes.\",\n                SyntaxWarning,\n                stacklevel=2,\n            )","sourceCodeStart":2162,"sourceCodeEnd":2198,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/losses/losses.py#L2162-L2198","documentation":"Error \"`axis` must be of type `int`. Received: axis={axis} of type {type(axis)}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/losses/losses.py:2180 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}