在进行参数初始化方式对训练的影响,就会涉及到pytorch的自定义参数初始化
参数初始化在不同的结构中定义也是不相同,下面以pytorch框架结构为例进行讲解
nn.Sequential
定义:一个有序的容器,神经网络模块将按照传入构造起的顺序依次被添加到计算图中执行,同时以神经网络模块为元素的有序字典也可以作为传入参数
例:
# Example of using Sequential
model = nn.Sequential(
nn.Conv2d(1,20,5),
nn.ReLU(),
nn.Conv2d(20,64,5),
nn.ReLU()
)
# Example of using Sequential with OrderedDict
model = nn.Sequential(OrderedDict([
('conv1', nn.Conv2d(1,20,5)),
('relu1', nn.ReLU()),
('conv2', nn.Conv2d(20,64,5)),
('relu2', nn.ReLU())
]))
图上所示:
nn.Sequential和nn.Sequential(OrederedDict())是等价的