# pytorch 反卷积 可视化_PyTorch中反卷积的用法

pytorch中的 2D 卷积层 和 2D 反卷积层 函数分别如下：

class torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, groups=1, bias=True)

class torch.nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, bias=True)

o = [ (i + 2p - k)/s ] +1 (1)

O : 为 output size

i: 为 input size

p: 为 padding size

k: 为kernel size

s: 为 stride size

[] 为下取整运算

(1) 当 S=1 时

i = o'

o = i'

i' = o' + 2p - k +1

o' = i' - 2p + k - 1 (2)

(2) 当 S>1 时

i' = [ (o' + 2p - k)/s ] +1

o'(0) = ( i' - 1) x s + k - 2p

o'(1) = o'(1) + 1

o'(2) = o'(1) + 2

...

o'(s-1) = o'(1) + s-1

o'(n) =o'(1) + n = ( i' - 1) x s + k - 2p + n,

n = {0, 1, 2...s-1}

(3) 实验验证

from torch import nn

from torch.nn import init

from torch.autograd import Variable

dconv = nn.ConvTranspose2d(in_channels=1, out_channels= 1, kernel_size=2, stride=2, padding=1,output_padding=0, bias= False)

init.constant(dconv.weight, 1)

print(dconv.weight)

input = Variable(torch.ones(1, 1, 2, 2))

print(input)

print(dconv(input))

Fractionally Strided Convolution

ConvTranspose2d(1, 3, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), output_padding=(1, 1))

12-12 8429
05-29 5389
03-06 5235
05-30 670
07-09 5915
01-20 1214
08-15 1584
09-23 1310
01-22 442
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客