1.
x = F.max_pool2d(x, kernel_size=3, stride=2, padding=1)
self.conv2 = nn.Conv2d(96, 96, kernel_size=3, stride=2, padding=1)
self.conv4_0 = nn.Conv2d(128, 128, kernel_size=5, stride=2, padding=2)
增大感受野的方法
主要的方法是从增加网络的深度出发(这也是为什么神经网络在初期越深的网络模型效果越好的原因如VGG16等)
pooling 池化
池化主要任务是对数据降维,减小网络参数,提升网络的计算效率,同时,池化也是增加感受野的方法之一,但在增加感受野的同时,伴随着分辨率的降低,图像细节损失
dilated conv空洞卷积
空洞卷积的出现为了解决pooling层增大感受野之后进行上采样(增加图像的分辨率)过程中,图像信息缺失问题。
图(a)是普通卷积的运算看到的感受野大小,卷积后的每个像素能看到的卷积前图片的区域为3x3,图(b)可以当成是使用卷积核为7x7进行卷积运算,但其中只有标记为红色的9个点参与计算(dilated为2),能看到的感受野范围是7x7大小,同理图(c)可以当成是使用卷积核为15x15进行卷积运算,但其中只有标记为红色的9个点参与计算(dilated为4),能看到的感受野范围是15x15大小.
同时,注明一下几点:
空洞卷积与普通卷积相比,增加了感受野,但是不会增加需要训练的参数的量,因为,感受野增加范围内的其他像素点是选择性的跳过,能看得到,但是不需要计算。
是选择性的跳过了部分的像素值进行卷积计算,并不是增加padding,填充像素0的操作。
在Pytorch中可以在torch.nn.Conv2D(,,,,,,,dilated=rate)实现。
from torch import nn
import torch.nn.init as init
def transform():
return Compose([
ToTensor(),
# Normalize((12,12,12),std = (1,1,1)),
])
arr = range(1,26)
arr = np.reshape(arr,[5,5])
arr = np.expand_dims(arr,2)
arr = arr.astype(np.float32)
# arr = arr.repeat(3,2)
print(arr.shape)
arr = transform()(arr)
arr = arr.unsqueeze(0)
print(arr)
conv1 = nn.Conv2d(1, 1, 3, stride=1, bias=False, dilation=1) # 普通卷积
conv2 = nn.Conv2d(1, 1, 3, stride=1, bias=False, dilation=2) # dilation就是空洞率,即间隔
init.constant_(conv1.weight, 1)
init.constant_(conv2.weight, 1)
out1 = conv1(arr)
out2 = conv2(arr)
print('standare conv:\n', out1.detach().numpy())
print('dilated conv:\n', out2.detach().numpy())
|