Open jerryandjune opened 1 year ago
class Conv(nn.Module): """Standard convolution with args(ch_in, ch_out, kernel, stride, padding, groups, dilation, activation).""" default_act = nn.SiLU() # -------------------------是这里吗?---------------------------
def __init__(self, c1, c2, k=1, s=1, p=None, g=1, d=1, act=True): """Initialize Conv layer with given arguments including activation.""" super().__init__() self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p, d), groups=g, dilation=d, bias=False) self.bn = nn.BatchNorm2d(c2) self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity() def forward(self, x): """Apply convolution, batch normalization and activation to input tensor.""" return self.act(self.bn(self.conv(x))) def forward_fuse(self, x): """Perform transposed convolution of 2D data.""" return self.act(self.conv(x))
class ConvTranspose(nn.Module): """Convolution transpose 2d layer.""" default_act = nn.SiLU() #-------------------------是这里吗?---------------------------
def __init__(self, c1, c2, k=2, s=2, p=0, bn=True, act=True): """Initialize ConvTranspose2d layer with batch normalization and activation function.""" super().__init__() self.conv_transpose = nn.ConvTranspose2d(c1, c2, k, s, p, bias=not bn) self.bn = nn.BatchNorm2d(c2) if bn else nn.Identity() self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity() def forward(self, x): """Applies transposed convolutions, batch normalization and activation to input.""" return self.act(self.bn(self.conv_transpose(x))) def forward_fuse(self, x): """Applies activation and convolution transpose operation to input.""" return self.act(self.conv_transpose(x))
请教一下,是上面的位置吗?谢谢
是的
好的,我试试,感谢
class Conv(nn.Module): """Standard convolution with args(ch_in, ch_out, kernel, stride, padding, groups, dilation, activation).""" default_act = nn.SiLU() # -------------------------是这里吗?---------------------------
class ConvTranspose(nn.Module): """Convolution transpose 2d layer.""" default_act = nn.SiLU() #-------------------------是这里吗?---------------------------
请教一下,是上面的位置吗?谢谢