2D deconvolution (i.e. transposed convolution). Arguments: x: Tensor or variable. kernel: kernel tensor. output_shape: 1D int tensor for the output shape. strides: strides tuple. padding: string, `"same"` or `"valid"`. data_format: string, `"channels_last"`
(x,
kernel,
output_shape,
strides=(1, 1),
padding='valid',
data_format=None,
dilation_rate=(1, 1))
| 4763 | |
| 4764 | @keras_export('keras.backend.conv2d_transpose') |
| 4765 | def conv2d_transpose(x, |
| 4766 | kernel, |
| 4767 | output_shape, |
| 4768 | strides=(1, 1), |
| 4769 | padding='valid', |
| 4770 | data_format=None, |
| 4771 | dilation_rate=(1, 1)): |
| 4772 | """2D deconvolution (i.e. |
| 4773 | |
| 4774 | transposed convolution). |
| 4775 | |
| 4776 | Arguments: |
| 4777 | x: Tensor or variable. |
| 4778 | kernel: kernel tensor. |
| 4779 | output_shape: 1D int tensor for the output shape. |
| 4780 | strides: strides tuple. |
| 4781 | padding: string, `"same"` or `"valid"`. |
| 4782 | data_format: string, `"channels_last"` or `"channels_first"`. |
| 4783 | dilation_rate: Tuple of 2 integers. |
| 4784 | |
| 4785 | Returns: |
| 4786 | A tensor, result of transposed 2D convolution. |
| 4787 | |
| 4788 | Raises: |
| 4789 | ValueError: if `data_format` is neither `channels_last` or |
| 4790 | `channels_first`. |
| 4791 | """ |
| 4792 | if data_format is None: |
| 4793 | data_format = image_data_format() |
| 4794 | if data_format not in {'channels_first', 'channels_last'}: |
| 4795 | raise ValueError('Unknown data_format: ' + str(data_format)) |
| 4796 | |
| 4797 | # `atrous_conv2d_transpose` only supports NHWC format, even on GPU. |
| 4798 | if data_format == 'channels_first' and dilation_rate != (1, 1): |
| 4799 | force_transpose = True |
| 4800 | else: |
| 4801 | force_transpose = False |
| 4802 | |
| 4803 | x, tf_data_format = _preprocess_conv2d_input(x, data_format, force_transpose) |
| 4804 | |
| 4805 | if data_format == 'channels_first' and tf_data_format == 'NHWC': |
| 4806 | output_shape = (output_shape[0], output_shape[2], output_shape[3], |
| 4807 | output_shape[1]) |
| 4808 | if output_shape[0] is None: |
| 4809 | output_shape = (shape(x)[0],) + tuple(output_shape[1:]) |
| 4810 | |
| 4811 | if isinstance(output_shape, (tuple, list)): |
| 4812 | output_shape = array_ops.stack(list(output_shape)) |
| 4813 | |
| 4814 | padding = _preprocess_padding(padding) |
| 4815 | if tf_data_format == 'NHWC': |
| 4816 | strides = (1,) + strides + (1,) |
| 4817 | else: |
| 4818 | strides = (1, 1) + strides |
| 4819 | |
| 4820 | if dilation_rate == (1, 1): |
| 4821 | x = nn.conv2d_transpose(x, kernel, output_shape, strides, |
| 4822 | padding=padding, |
nothing calls this directly
no test coverage detected