nn.ConvTranspose2d()
在由多个输入平面组成的输入图像上应用二维转置卷积运算符。
该模块可以看作是Conv2d相对于其输入的梯度。它也被称为分数步法卷积或反卷积(尽管它不是实际的反卷积运算)。
参数
in_channels(int)–输入图像中的通道数
out_channels(int)–卷积产生的通道数
padding(int或tuple,可选)– 零填充将添加到输入中每个维度的两侧。默认值:0
dilation * (kernel_size - 1) - padding
groups(int,可选)–从输入通道到输出通道的阻塞连接数。默认值:1
bias(bool,可选)–如果为
True
,则向输出添加可学习的偏见。默认:True
维度
- Input:
- Output:
例子
>>> # With square kernels and equal stride
>>> m = nn.ConvTranspose2d(16, 33, 3, stride=2)
>>> # non-square kernels and unequal stride and with padding
>>> m = nn.ConvTranspose2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2))
>>> input = torch.randn(20, 16, 50, 100)
>>> output = m(input)
>>> # exact output size can be also specified as an argument
>>> input = torch.randn(1, 16, 12, 12)
>>> downsample = nn.Conv2d(16, 16, 3, stride=2, padding=1)
>>> upsample = nn.ConvTranspose2d(16, 16, 3, stride=2, padding=1)
>>> h = downsample(input)
>>> h.size()
torch.Size([1, 16, 6, 6])
>>> output = upsample(h, output_size=input.size())
>>> output.size()
torch.Size([1, 16, 12, 12])