日期:2020-2-15
pytorch中用于归一化的函数为nn.BatchNorm2d
文档如下:
转载一片非常好的例子:
https://blog.csdn.net/tmk_01/article/details/80679549
调用的时候有一点很重要,就是要参数要与特征数(features)一致
torch.nn.BatchNorm2d(channels)
举个例子:
在一处神经网络
def contracting_block(self, in_channels, out_channels, kernel_size=3):
block = torch.nn.Sequential(
torch.nn.Conv2d(kernel_size=kernel_size, in_channels=in_channels, out_channels=out_channels),
torch.nn.ReLU(),
torch.nn.BatchNorm2d(out_channels),
torch.nn.Conv2d(kernel_size=kernel_size, in_channels=out_channels, out_channels=out_channels),
torch.nn.ReLU(),
torch.nn.BatchNorm2d(out_channels),
)
return block
便是如此