PaddlePaddle(飞浆)的图像分割7天训练营class4学习笔记
Deeplab系列有V1,v2,v3。
具体要求:
语义分割是对图像做密集的分割任务,分割每个像素到指定的类别上;
将图像分割成几个有意义的目标;
给对象分配指定的类别标签。
Deeplab v1的网络结构:
Deeplab v2的网络结构:
Deeplab v2 ASPP结构
使用多尺度进行空洞卷积,在经过1*1的卷积之后连接起来。多尺度特征提取,得到全局和局部特征
Deeeplab v3的网络结构:
ASPP升级模块:
实现V3:
代码:
Deeplab部分:
class Deeplab(Layer):def __init__(self,num_classes=59):super(Deeplab,self).__init__()resnet = ReseNet50(pretrained=False)self.layer0 = fluid.dygraph.Sequential(resnet.conv,resnet.pool2d_max)self.layer1 = resnet.layer1self.layer2 = resnet.layer2self.layer3 = resnet.layer3self.layer4 = resnet.layer4#multgridself.layer5 = resnet.layer5self.layer6 = resnet.layer6self.layer7 = resnet.layer7feature_dim = 2048self.classifier = DeepLabHead(feature_dim,num_classes)def forward(self, inputs):n,c,h,w = inputs.shapex = self.layer0(inputs)x = self.layer1(x)x = self.layer2(x)x = self.layer3(x)x = self.layer4(x)x = self.layer5(x)x = self.layer6(x)x = self.layer7(x)x = self.classifier(x)x = fluid.layers.interpolate(x,(h,w),align_corners=False)return x
ASPP结构部分:
class ASPPModule(layer):def __init__(self,num_channels,num_filters,rates):super(ASPPModule,self).__init__()self.features = []self.features.append(fluid.dygraph.Sequential(Conv2D(num_channels, num_filters,1),BatchNorm(num_filters,act='relu')))self.features.append(ASPPPolling(num_channels,num_filters))for r in rates:self.features.append(ASPPConv(num_channels,num_filters,r))self.project = fluid.dygraph.Sequential(Conv2D(num_filters*(2+len(rates)), num_filters, 1),BatchNorm(num_filters,act='relu'))def forward(self,inputs):res = []for op in self.features:res.append(op(inputs))x = fluid.layers.concat(res,axis=1)x = self.project(x)return x
总结:空间金字塔池化模块(SPP)和编码解码结构,用于语义分割的深度网络结构。SPP利用多种比例和多种有效感受野的不同分辨率特征处理,来挖掘多尺度的上下文内容信息,编解码结构逐步重构空间信息来更好的捕捉物体边界。