本博文以 Dense Block 为例,Pytorch 为 DL 框架,最终计算模块参数量方法如下:
import torch
import torch.nn as nn
class Norm_Conv(nn.Module):
def __init__(self,in_channel):
super(Norm_Conv,self).__init__()
self.layers = nn.Sequential(
nn.Conv2d(in_channel,in_channel,3,1,1),
nn.ReLU(True),
nn.BatchNorm2d(in_channel),
nn.Conv2d(in_channel,in_channel,3,1,1),
nn.ReLU(True),
nn.BatchNorm2d(in_channel),
nn.Conv2d(in_channel,in_channel,3,1,1),
nn.ReLU(True),
nn.BatchNorm2d(in_channel))
def forward(self,input):
out = self.layers(input)
return out
class DenseBlock_Norm(nn.Module):
def __init__(self,in_channel):
super(DenseBlock_Norm,self).__init__()
self.first_layer = nn.Sequential(nn.Conv2d(in_channel,in_channel,3,1,1),
nn.ReLU(True),