反卷积

计算输入张量到输出张量的 2D 或 3D 反卷积。

注意

此层也称为 ConvTranspose。

属性

kernel_size 包含 2 或 3 个元素的数组,描述每个空间维度中反卷积核的大小。数组的大小(2 或 3)决定了反卷积的类型,2D 或 3D。

padding_mode 填充模式。填充模式可以是以下之一

\[\begin{split}\begin{gather} I = \text{dimensions of input image.} \\ B = \text{pre-padding, before the image data. For deconvolution, pre-padding is set before output.} \\ A = \text{post-padding, after the image data. For deconvolution, post-padding is set after output.} \\ P = \text{delta between input and output} \\ S = \text{stride} \\ F = \text{filter} \\ O = \text{output} \\ D = \text{dilation} \\ DK = 1 + D \cdot (F - 1) \\ \end{gather}\end{split}\]
  • EXPLICIT_ROUND_DOWN 使用显式填充,向下舍入输出大小。
    \(O = (I - 1) \cdot S + DK - (B + A)\)
  • EXPLICIT_ROUND_UP 使用显式填充,向上舍入输出大小。
    \(O = (I - 1) \cdot S + DK - (B + A)\)
  • SAME_UPPER 使用 SAME 填充,其中 \(\text{pre-padding} \leq \text{post-padding}\)
    \(\begin{gather}O = \min\left(I \cdot S, (I - 1) \cdot S + DK\right) \\ P = \max\left(DK - S, 0\right) \\ B = \lfloor\frac{P}{2}\rfloor \\ A = P - B \end{gather}\)
  • SAME_LOWER 使用 SAME 填充,其中 \(\text{pre-padding} \geq \text{post-padding}\)
    \(\begin{gather}O = \min\left(I \cdot S, (I - 1) \cdot S + DK\right) \\ P = \max\left(DK - S, 0\right) \\ A = \lfloor\frac{P}{2}\rfloor \\ B = P - A \end{gather}\)

pre_padding 每个空间维度要使用的前填充量。

post_padding 每个空间维度要使用的后填充量。

stride 每个空间维度要使用的步幅。

dilation 每个空间维度的扩张因子。

num_output_maps 该层输出中的输出特征图的数量。

num_groups 该层输出中的组数。当使用 int8 数据类型时,输入和输出的组数都必须是 4 的倍数。

kernel_weights 指向该层权重的指针。

bias_weights 指向该层偏置的指针。

输入

input:类型为 T 的张量。

输出

output:类型为 T 的张量。

数据类型

Tint8float16float32

形状信息

input 是一个形状为 \([a_0,...,a_n]\) 的张量

kernel_size 是一个数组 \([k_0,...,k_{m-1}], m \in [2,3]\)

output 是一个形状为 \([b_0,...,b_n]\) 的张量,其中

\[\begin{split}s_j - \text{stride at spatial dimension j}\\ k_j - \text{kernel at spatial dimension j}\\ d_j - \text{dilation at spatial dimension j}\\ p_j^{pre} - \text{pre padding at spatial dimension j}\\ p_j^{post} - \text{post padding at spatial dimension j}\\\end{split}\]
\[\begin{split}b_i = \begin{cases} a_i, & 0 \leq i < n-m \\ (a_i−1) \cdot s_j + 1 + d_j \cdot (k_j - 1) − p_j^{pre} - p_j^{post}, & n-m \leq i < n, & j=i-(n-m) \end{cases}\end{split}\]

体积限制

inputoutput 最多可以有 \(2^{31}\) 个元素。

DLA 支持

DLA FP16 支持 2D 反卷积。

DLA INT8 支持 2D 非分组反卷积。

示例

反卷积
in1 = network.add_input("input1", dtype=trt.float32, shape=(1, 1, 3, 3))
layer = network.add_deconvolution_nd(
    in1, num_output_maps=1, kernel_shape=(3, 3), kernel=np.ones(shape=(1, 1, 3, 3), dtype=np.float32)
)
network.mark_output(layer.get_output(0))

inputs[in1.name] = np.array([[[[-3.0, -2.0, -1.0], [0.0, 1.0, 2.0], [2.0, 5.0, 6.0]]]])

outputs[layer.get_output(0).name] = layer.get_output(0).shape

expected[layer.get_output(0).name] = np.array(
    [
        [
            [
                [-3.0, -5.0, -6.0, -3.0, -1.0],
                [-3.0, -4.0, -3.0, 0.0, 1.0],
                [-1.0, 3.0, 10.0, 11.0, 7.0],
                [2.0, 8.0, 16.0, 14.0, 8.0],
                [2.0, 7.0, 13.0, 11.0, 6.0],
            ]
        ]
    ]
)

C++ API

有关 C++ IDeconvolutionLayer 算子的更多信息,请参阅 C++ IDeconvolutionLayer 文档

Python API

有关 Python IDeconvolutionLayer 算子的更多信息,请参阅 Python IDeconvolutionLayer 文档