PSPNet
It is a semantic segmentation model incorporating suitable global features

Scene Parsing

Scene parsing is the process of segmenting and parsing an image into various visual areas that correspond to semantic categories such as sky, road, person, and bed.
Scene parsing on ADE20K dataset.
From the figure above we see that there are several issues for complex-scene parsing. The first row shows the issue of mismatched relationship โ€“ cars are seldom over water than boats. The second row shows confusion categories where class โ€œbuildingโ€ is easily confused as โ€œskyscraperโ€. The third row illustrates inconspicuous classes. In terms of colour and texture, the pillow in this case is extremely comparable to the bedsheet. These inconspicuous objects are easily misclassified by Fully Convolutional Network (FCN).
A deep network with a suitable global-scene-level prior can much improve the performance of scene parsing, and this is where PSPNet comes in, it is able to capture the context of the whole image to classify the object as a boat.

Encoder network

The PSPNet encoder contains the CNN backbone with dilated convolutions along with the pyramid pooling module. The last two blocks of the backbone have Dilated convolution layers with dilation rate 2 and 4 respectively.
In Model Playground, we can select feature extraction (encoding) network to use as either Resnet or EffiecientNet. We can also select the depth and weights in the Resnet variant.

Dropout

Dropout refers to randomly ignoring neurons making the network less sensitive to the specific weights of neurons, which in turn results in a network that is capable of better generalization and is less likely to overfit the training data. It is the probability of an element to be zeroed in the decoder output (right before segmentation head)
In Model Playground PSPNet dropout can be set between 0 and 1.

Pyramid Pooling Module

Proposed architecture design of PSPNet by Zhao et al.
Given an input image, PSPNet uses a pretrained ResNet model with the dilated network strategy to extract the feature map of the last convolutional layer. On top of this feature map, the pyramid pooling module is applied to harvest different sub-region representations. This is followed by upsampling on the pooled features to make them the same size as the original feature map. Afterward, these upsampled maps are concatenated with the original feature map to be passed to the decoder carrying both local and global context information which is fed into a convolution layer to get the final per-pixel prediction.

PSP out channels

In Model Playground the number of out channels in the PSP decoder can be set.

Weights

It's the weights to use for model initialization, and in Model Playground Random Initialization of weights is used.

Code Implementation

1
โ€‹
2
class PSPModule(nn.Module):
3
def __init__(self, features, out_features=1024, sizes=(1, 2, 3, 6)):
4
super().__init__()
5
self.stages = []
6
self.stages = nn.ModuleList([self._make_stage(features, size) for size in sizes])
7
self.bottleneck = nn.Conv2d(features * (len(sizes) + 1), out_features, kernel_size=1)
8
self.relu = nn.ReLU()
9
โ€‹
10
def _make_stage(self, features, size):
11
prior = nn.AdaptiveAvgPool2d(output_size=(size, size))
12
conv = nn.Conv2d(features, features, kernel_size=1, bias=False)
13
return nn.Sequential(prior, conv)
14
โ€‹
15
def forward(self, feats):
16
h, w = feats.size(2), feats.size(3)
17
priors = [F.upsample(input=stage(feats), size=(h, w), mode='bilinear') for stage in self.stages] + [feats]
18
bottle = self.bottleneck(torch.cat(priors, 1))
19
return self.relu(bottle)
20
โ€‹
21
โ€‹
22
class PSPUpsample(nn.Module):
23
def __init__(self, in_channels, out_channels):
24
super().__init__()
25
self.conv = nn.Sequential(
26
nn.Conv2d(in_channels, out_channels, 3, padding=1),
27
nn.BatchNorm2d(out_channels),
28
nn.PReLU()
29
)
30
โ€‹
31
def forward(self, x):
32
h, w = 2 * x.size(2), 2 * x.size(3)
33
p = F.upsample(input=x, size=(h, w), mode='bilinear')
34
return self.conv(p)
35
โ€‹
36
โ€‹
37
class PSPNet(nn.Module):
38
def __init__(self, n_classes=18, sizes=(1, 2, 3, 6), psp_size=2048, deep_features_size=1024, backend='resnet34',
39
pretrained=True):
40
super().__init__()
41
self.feats = getattr(extractors, backend)(pretrained)
42
self.psp = PSPModule(psp_size, 1024, sizes)
43
self.drop_1 = nn.Dropout2d(p=0.3)
44
โ€‹
45
self.up_1 = PSPUpsample(1024, 256)
46
self.up_2 = PSPUpsample(256, 64)
47
self.up_3 = PSPUpsample(64, 64)
48
โ€‹
49
self.drop_2 = nn.Dropout2d(p=0.15)
50
self.final = nn.Sequential(
51
nn.Conv2d(64, n_classes, kernel_size=1),
52
nn.LogSoftmax()
53
)
54
โ€‹
55
self.classifier = nn.Sequential(
56
nn.Linear(deep_features_size, 256),
57
nn.ReLU(),
58
nn.Linear(256, n_classes)
59
)
60
โ€‹
61
def forward(self, x):
62
f, class_f = self.feats(x)
63
p = self.psp(f)
64
p = self.drop_1(p)
65
โ€‹
66
p = self.up_1(p)
67
p = self.drop_2(p)
68
โ€‹
69
p = self.up_2(p)
70
p = self.drop_2(p)
71
โ€‹
72
p = self.up_3(p)
73
p = self.drop_2(p)
74
โ€‹
75
auxiliary = F.adaptive_max_pool2d(input=class_f, output_size=(1, 1)).view(-1, class_f.size(1))
76
โ€‹
77
return self.final(p), self.classifier(auxiliary)
Copied!

Further Resources:

PSPNet by Zhao et al. : https://arxiv.org/abs/1612.01105
Last modified 4mo ago