nn.ConvTranspose2d()
在由多個(gè)輸入平面組成的輸入圖像上應(yīng)用二維轉(zhuǎn)置卷積運(yùn)算符。
該模塊可以看作是Conv2d相對(duì)于其輸入的梯度赛不。它也被稱為分?jǐn)?shù)步法卷積或反卷積(盡管它不是實(shí)際的反卷積運(yùn)算)惩嘉。
參數(shù)
in_channels(int)–輸入圖像中的通道數(shù)
out_channels(int)–卷積產(chǎn)生的通道數(shù)
padding(int或tuple文黎,可選)– 零填充將添加到輸入中每個(gè)維度的兩側(cè)惹苗。默認(rèn)值:0
dilation * (kernel_size - 1) - padding
output_padding(int或tuple,可選)–在輸出形狀的每個(gè)尺寸的一側(cè)添加的附加大小耸峭。默認(rèn)值:0
groups(int桩蓉,可選)–從輸入通道到輸出通道的阻塞連接數(shù)。默認(rèn)值:1
bias(bool劳闹,可選)–如果為
True
院究,則向輸出添加可學(xué)習(xí)的偏見。默認(rèn):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])