{"record":{"id":"f452c609a2508701","repo":"keras-team/keras","slug":"the-number-of-input-channels-must-match-the-kernel","errorCode":null,"errorMessage":"The number of input channels must match the kernel's input channels. Received: input channels={input_channels}, kernel input channels={kernel_input_channels}, data_format='{data_format}'.","messagePattern":"The number of input channels must match the kernel's input channels\\. Received: input channels=(.+?), kernel input channels=(.+?), data_format='(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/common/backend_utils.py","lineNumber":392,"sourceCode":"    \"\"\"Validate a conv input against its kernel shape.\n\n    Used by `conv`, `depthwise_conv`, and `separable_conv` — all share the\n    convention that the kernel's input-channel dimension is `kernel.shape[-2]`.\n    Produces a clear error message before the backend op raises its own\n    implementation-specific one.\n    \"\"\"\n    input_channels = (\n        inputs.shape[-1] if data_format == \"channels_last\" else inputs.shape[1]\n    )\n    kernel_input_channels = kernel.shape[-2]\n    # Only validate when both dimensions are concrete Python ints. Dynamic\n    # dimensions can come in forms other than `None` during tracing.\n    if (\n        isinstance(input_channels, int)\n        and isinstance(kernel_input_channels, int)\n        and input_channels != kernel_input_channels\n    ):\n        raise ValueError(\n            \"The number of input channels must match the kernel's input \"\n            f\"channels. Received: input channels={input_channels}, kernel \"\n            f\"input channels={kernel_input_channels}, \"\n            f\"data_format='{data_format}'.\"\n        )\n\n\ndef check_conv_transpose_input_channels(inputs, kernel, data_format):\n    \"\"\"Validate a conv_transpose input against its kernel shape.\n\n    `conv_transpose` kernels use the layout\n    `(spatial..., out_channels, in_channels)`, so the input-channel dimension\n    is at `kernel.shape[-1]` (vs. `kernel.shape[-2]` for regular conv).\n    \"\"\"\n    input_channels = (\n        inputs.shape[-1] if data_format == \"channels_last\" else inputs.shape[1]\n    )\n    kernel_input_channels = kernel.shape[-1]","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/common/backend_utils.py#L374-L410","documentation":"Error \"The number of input channels must match the kernel's input channels. Received: input channels={input_channels}, kernel input channels={kernel_input_channels}, data_format='{data_format}'.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/common/backend_utils.py:392 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"}