{"record":{"id":"a7dacc488ad1733b","repo":"keras-team/keras","slug":"expected-the-2-dimensions-of-the-dilation-rate-a","errorCode":null,"errorMessage":"Expected the 2 dimensions of the `dilation_rate` argument to be equal to each other. Received: dilation_rate={dilation_rate}","messagePattern":"Expected the 2 dimensions of the `dilation_rate` argument to be equal to each other\\. Received: dilation_rate=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/legacy/backend.py","lineNumber":586,"sourceCode":"\n    padding = _preprocess_padding(padding)\n    if tf_data_format == \"NHWC\":\n        strides = (1,) + strides + (1,)\n    else:\n        strides = (1, 1) + strides\n\n    if dilation_rate == (1, 1):\n        x = tf.compat.v1.nn.conv2d_transpose(\n            x,\n            kernel,\n            output_shape,\n            strides,\n            padding=padding,\n            data_format=tf_data_format,\n        )\n    else:\n        if dilation_rate[0] != dilation_rate[1]:\n            raise ValueError(\n                \"Expected the 2 dimensions of the `dilation_rate` argument \"\n                \"to be equal to each other. \"\n                f\"Received: dilation_rate={dilation_rate}\"\n            )\n        x = tf.nn.atrous_conv2d_transpose(\n            x, kernel, output_shape, rate=dilation_rate[0], padding=padding\n        )\n    if data_format == \"channels_first\" and tf_data_format == \"NHWC\":\n        x = tf.transpose(x, (0, 3, 1, 2))  # NHWC -> NCHW\n    return x\n\n\n@keras_export(\"keras._legacy.backend.conv3d\")\ndef conv3d(\n    x,\n    kernel,\n    strides=(1, 1, 1),\n    padding=\"valid\",","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/legacy/backend.py#L568-L604","documentation":"The atrous (dilated) path of the legacy conv2d_transpose() is implemented via tf.nn.atrous_conv2d_transpose, which takes a single scalar rate. Therefore dilation_rate must be square: dilation_rate[0] == dilation_rate[1]. Non-square dilation forces a slower transpose-based path, so Keras rejects it up front rather than silently changing performance semantics.","triggerScenarios":"keras._legacy.backend.conv2d_transpose(x, kernel, output_shape, strides=(2,2), dilation_rate=(1,2)) — or any (r1, r2) with r1 != r2 — when the code takes the non-force_transpose branch (channels_last, or strides equal to dilation).","commonSituations":"Ported deconvolution layers with anisotropic dilation from other frameworks; config files specifying asymmetric dilation rates that worked elsewhere; defaults copied from a Conv2D layer whose dilation was then reused for the transpose.","solutions":["Use a square dilation rate, e.g. dilation_rate=(2,2)","If anisotropic dilation is genuinely required, decompose into two transposed convolutions with square rates or pad+conv manually","Set dilation_rate=(1,1) if dilation was copied in accidentally and is not needed"],"exampleFix":"// before\nout = K.conv2d_transpose(x, k, shape, dilation_rate=(1, 3))  # ValueError\n\n// after\nout = K.conv2d_transpose(x, k, shape, dilation_rate=(3, 3))","handlingStrategy":"validation","validationCode":"if dilation_rate is not None:\n    assert dilation_rate[0] == dilation_rate[1], f'dilation_rate must be square, got {dilation_rate}'","typeGuard":"def is_square_dilation(d) -> bool:\n    return d[0] == d[1]","tryCatchPattern":"except ValueError as e:\n    if 'dilation_rate' in str(e):\n        out = K.conv2d_transpose(x, k, output_shape, dilation_rate=(d[0], d[0]))\n    else:\n        raise","preventionTips":["Default dilation_rate to (1,1) in wrapper layers","Validate dilation symmetry wherever conv params are parsed","Document the atrous path's square-rate limitation near the call site"],"tags":["keras","tensorflow","conv2d-transpose","dilation","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}