PyTorch——解决报错“RuntimeError: running_mean should contain *** elements not ***”

问题描述:在使用PyTorch进行编程的时候,通常需要在conv后面加入BN层,经常遇到一种报错就是:“RuntimeError: running_mean should contain *** elements not ***”;

例如·:

self.conv1 = torch.nn.Conv2d(in_channels=1,out_channels=10,kernel_size=3)
self.conv2 = torch.nn.Conv2d(in_channels=10,out_channels=20,kernel_size=3)
self.conv3 = torch.nn.Conv2d(in_channels=20, out_channels=40, kernel_size=3)

self.batch1 = torch.nn.BatchNorm2d(10)##要和conv1的out_channels保持一致
self.batch2 = torch.nn.BatchNorm2d(20)##要和conv2的out_channels保持一致
self.batch3 = torch.nn.BatchNorm2d(40)##要和conv3的out_channels保持一致

你可能感兴趣的:(pytorch,pytorch,深度学习,人工智能)