带dilation的卷积输出尺寸计算公式(附代码)
程序员文章站
2022-10-27 18:20:02
带dilation的卷积输出尺寸计算公式K′=dilation+(kernel−1)⋅(dilation−1)K'=dilation+(kernel-1)\cdot(dilation-1)K′=dilation+(kernel−1)⋅(dilation−1)Wout=win−K′+2paddingstride+1W_{out}=\frac{w_{in}-K'+2padding}{stride}+1Wout=stridewin−K′+2padding+1举例# -*- coding: utf-8...
带dilation的卷积输出尺寸计算公式
举例
# -*- coding: utf-8 -*-
import torch
import torch.nn as nn
def default_conv(in_channels,out_channels,kernel_size,stride,padding,dilation,bias=True):
return nn.Conv2d(in_channels = in_channels,
out_channels = out_channels,
kernel_size = kernel_size, # 3
stride = stride, # 1
padding = padding, # 5
dilation = dilation, # 5
bias=bias)
class ShizuoNet(nn.Module):
def __init__(self, conv=default_conv,n_feats=32):
super(ShizuoNet,self).__init__()
self.convA = conv(1,32,3,1,5,5)
def forward(self,x):
print(x.shape)
y = self.convA(x) # torch.Size([2, 1, 80, 80])
print(y.shape) # torch.Size([2, 32, 80, 80])
return y
def main():
net = ShizuoNet()
from torchsummary import summary
summary(net, (1, 80, 80))
if __name__ == "__main__":
main()
本文地址:https://blog.csdn.net/qq_36937684/article/details/107678041