测试代码由此开始:
class Net(nn.Module):
def __init__(self):
super(Net,self).__init__()
self.conv1 = nn.Conv2d(3, 6, kernel_size=3, padding=1)
self.bn1 = nn.BatchNorm2d(6)
self.conv2 = nn.Conv2d(6,8,kernel_size=3,padding=1)
self.relu = nn.ReLU(inplace=True)
def forward(self,x):
x = self.conv1(1)
x = self.bn1(x)
x = self.conv2(x)
x = self.relu(x)
return x
net = Net()
pdb.set_trace()
pdb中的net 或者 print(net) -> 输出模型具体框架
net.parameters() -> 生成器generater,用循环拿到参数
print([name.shape for name in net.parameters()]) -> name是每个层的参数层数值,每个name是类型是torch.nn.parameter.Parameter,name.shape<