{"record":{"id":"f10f911e497a60af","repo":"keras-team/keras","slug":"row-axis-col-axis-and-channel-axis-must-be","errorCode":null,"errorMessage":"'row_axis', 'col_axis', and 'channel_axis' must be distinct","messagePattern":"'row_axis', 'col_axis', and 'channel_axis' must be distinct","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/preprocessing/image.py","lineNumber":1795,"sourceCode":"    shear=0,\n    zx=1,\n    zy=1,\n    row_axis=1,\n    col_axis=2,\n    channel_axis=0,\n    fill_mode=\"nearest\",\n    cval=0.0,\n    order=1,\n):\n    \"\"\"Applies an affine transformation specified by the parameters given.\n\n    DEPRECATED.\n    \"\"\"\n    # Input sanity checks:\n    # 1. x must 2D image with one or more channels (i.e., a 3D tensor)\n    # 2. channels must be either first or last dimension\n    if np.unique([row_axis, col_axis, channel_axis]).size != 3:\n        raise ValueError(\n            \"'row_axis', 'col_axis', and 'channel_axis' must be distinct\"\n        )\n\n    # shall we support negative indices?\n    valid_indices = set([0, 1, 2])\n    actual_indices = set([row_axis, col_axis, channel_axis])\n    if actual_indices != valid_indices:\n        raise ValueError(\n            f\"Invalid axis' indices: {actual_indices - valid_indices}\"\n        )\n\n    if x.ndim != 3:\n        raise ValueError(\"Input arrays must be multi-channel 2D images.\")\n    if channel_axis not in [0, 2]:\n        raise ValueError(\n            \"Channels are allowed and the first and last dimensions.\"\n        )\n","sourceCodeStart":1777,"sourceCodeEnd":1813,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/preprocessing/image.py#L1777-L1813","documentation":"apply_affine_transform requires three distinct axis arguments (row_axis, col_axis, channel_axis) that together describe which dimensions of a 3D image tensor are rows, columns, and channels. If any two are equal the mapping is ambiguous, so Keras raises this ValueError before doing any work. It lives in the legacy keras.preprocessing.image module.","triggerScenarios":"Calling apply_affine_transform (directly or via random_rotation, random_shift, random_shear, random_zoom, apply_transform) with two equal axis values, e.g. row_axis=1, col_axis=1, channel_axis=2, or a copy-paste error repeating the same default twice.","commonSituations":"Hand-writing axis permutations for channels-first vs channels-last images when porting old scipy.ndimage-style augmentation code, or loops that assign axis indices programmatically and accidentally alias two of them.","solutions":["Set the three axes to a permutation of 0, 1, 2, e.g. row_axis=0, col_axis=1, channel_axis=2 (channels-last) or row_axis=2, col_axis=0, channel_axis=1 (channels-first)","Check computed/looped axis assignments for duplicates before calling","For the random_* wrappers, prefer their channel_axis argument instead of manual axis triples"],"exampleFix":"# before\napply_affine_transform(img, theta=15, row_axis=0, col_axis=0, channel_axis=2)\n# after\napply_affine_transform(img, theta=15, row_axis=0, col_axis=1, channel_axis=2)","handlingStrategy":"validation","validationCode":"axes = {row_axis, col_axis, channel_axis}\nif len(axes) != 3:\n    raise ValueError('axis arguments must be distinct')","typeGuard":"def valid_axes(r, c, ch):\n    return len({r, c, ch}) == 3","tryCatchPattern":null,"preventionTips":["Derive the axis triple from a single permutation constant instead of three independent variables"],"tags":["keras","preprocessing","image","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}