昨天一直很费解就是如下的参数:
class Conv(nn.Module):
# Standard convolution
def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups
super(Conv, self).__init__()
self.conv = nn.Conv2d(c1, c2, k, padding=1)
self.bn = nn.BatchNorm2d(c2)
self.act = nn.LeakyReLU(0.1) if act is True else (act if isinstance(act, nn.Module) else nn.Identity())
def forward(self, x):
return self.conv(x)
def fuseforward(self, x):
return self.act(self.conv(x))
if __name__ == "__main__":
temp_conv = Conv(3, 32, 3)
tp = sum([val.numel() for val in temp_conv.parameters()])
print(tp)
结果是:
960,跟别人代码打印不一样,查了半天,然后一个一个打印,发现 Conv2d 的参数 860,BatchNorm2d 是64, LeakyReLU 参数为 0,
BathNorm的参数是64