欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

带dilation的卷积输出尺寸计算公式(附代码)

程序员文章站 2022-03-27 12:57:22
带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的卷积输出尺寸计算公式

K=kernel+(kernel1)(dilation1)K'=kernel+(kernel-1)\cdot(dilation-1)
Wout=winK+2paddingstride+1W_{out}=\frac{w_{in}-K'+2padding}{stride}+1

举例

# -*- 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