{"record":{"id":"90ba5629181e76af","repo":"keras-team/keras","slug":"invalid-output-padding-argument-each-value-in","errorCode":null,"errorMessage":"Invalid `output_padding` argument. Each value in `output_padding` must be strictly less than the corresponding `strides` value.\nAt index {i}, `output_padding` is {op} and `strides` is {s}.\nReceived: output_padding={self.output_padding}, strides={self.strides}.","messagePattern":"Invalid `output_padding` argument\\. Each value in `output_padding` must be strictly less than the corresponding `strides` value\\.\nAt index (.+?), `output_padding` is (.+?) and `strides` is (.+?)\\.\nReceived: output_padding=(.+?), strides=(.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/convolutional/base_conv_transpose.py","lineNumber":168,"sourceCode":"                    raise ValueError(\n                        \"`output_padding` must be strictly less than \"\n                        f\"`strides` for all dimensions. At dimension {i}, \"\n                        f\"`output_padding` is {op} but `strides` is {s}. \"\n                        f\"Received: output_padding={self.output_padding}, \"\n                        f\"strides={self.strides}\"\n                    )\n\n        if max(self.strides) > 1 and max(self.dilation_rate) > 1:\n            raise ValueError(\n                \"`strides > 1` not supported in conjunction with \"\n                f\"`dilation_rate > 1`. Received: strides={self.strides} and \"\n                f\"dilation_rate={self.dilation_rate}\"\n            )\n\n        if self.output_padding is not None:\n            for i, (op, s) in enumerate(zip(self.output_padding, self.strides)):\n                if op >= s:\n                    raise ValueError(\n                        \"Invalid `output_padding` argument. \"\n                        \"Each value in `output_padding` must be strictly \"\n                        \"less than the corresponding `strides` value.\\n\"\n                        f\"At index {i}, `output_padding` is {op} and `strides` \"\n                        f\"is {s}.\\n\"\n                        f\"Received: output_padding={self.output_padding}, \"\n                        f\"strides={self.strides}.\"\n                    )\n\n    def build(self, input_shape):\n        if self.data_format == \"channels_last\":\n            channel_axis = -1\n            input_channel = input_shape[-1]\n        else:\n            channel_axis = 1\n            input_channel = input_shape[1]\n        self.input_spec = InputSpec(\n            min_ndim=self.rank + 2, axes={channel_axis: input_channel}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/convolutional/base_conv_transpose.py#L150-L186","documentation":"In transpose convolutions, output_padding adds extra size to the output shape and must be strictly smaller than the stride per spatial dimension, otherwise the shape formula is ambiguous/invalid. The constructor validates each (output_padding[i], strides[i]) pair and raises when output_padding[i] >= strides[i].","triggerScenarios":"Creating Conv2DTranspose/Conv1DTranspose/Conv3DTranspose with output_padding=(2,2) and strides=(2,2), or any index where the padding value is not strictly less than the stride.","commonSituations":"Porting PyTorch nn.ConvTranspose2d configs where output_padding equals stride; trying to hit an exact output size and overshooting the padding value.","solutions":["Set each output_padding[i] strictly less than strides[i] (commonly strides[i]-1).","If targeting an exact output size, adjust padding/cropping instead of output_padding.","Precompute in config: all(op < s for op, s in zip(output_padding, strides))."],"exampleFix":"# before\nkeras.layers.Conv2DTranspose(64, 3, strides=2, padding='same', output_padding=(2, 2))\n\n# after\nkeras.layers.Conv2DTranspose(64, 3, strides=2, padding='same', output_padding=(1, 1))","handlingStrategy":"validation","validationCode":"assert all(op < s for op, s in zip(output_padding, strides)), 'output_padding must be < strides elementwise'","typeGuard":"def valid_output_padding(output_padding, strides) -> bool:\n    return all(op < s for op, s in zip(output_padding, strides))","tryCatchPattern":null,"preventionTips":["Keep output_padding at strides-1 or less","Assert config before layer construction"],"tags":["keras","transposed-conv","output-padding","shape-mismatch"],"backgroundTag":"invalid-convolution-arguments","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}