26
26
class FastSCNN (nn .Layer ):
27
27
"""
28
28
The FastSCNN implementation based on PaddlePaddle.
29
-
30
29
As mentioned in the original paper, FastSCNN is a real-time segmentation algorithm (123.5fps)
31
30
even for high resolution images (1024x2048).
32
-
33
31
The original article refers to
34
32
Poudel, Rudra PK, et al. "Fast-scnn: Fast semantic segmentation network"
35
33
(https://arxiv.org/pdf/1902.04502.pdf).
36
-
37
34
Args:
38
35
num_classes (int): The unique number of target classes.
39
36
enable_auxiliary_loss (bool, optional): A bool value indicates whether adding auxiliary loss.
@@ -95,9 +92,7 @@ def init_weight(self):
95
92
class LearningToDownsample (nn .Layer ):
96
93
"""
97
94
Learning to downsample module.
98
-
99
95
This module consists of three downsampling blocks (one conv and two separable conv)
100
-
101
96
Args:
102
97
dw_channels1 (int, optional): The input channels of the first sep conv. Default: 32.
103
98
dw_channels2 (int, optional): The input channels of the second sep conv. Default: 48.
@@ -132,10 +127,8 @@ def forward(self, x):
132
127
class GlobalFeatureExtractor (nn .Layer ):
133
128
"""
134
129
Global feature extractor module.
135
-
136
130
This module consists of three InvertedBottleneck blocks (like inverted residual introduced by MobileNetV2) and
137
131
a PPModule (introduced by PSPNet).
138
-
139
132
Args:
140
133
in_channels (int, optional): The number of input channels to the module. Default: 64.
141
134
block_channels (tuple, optional): A tuple represents output channels of each bottleneck block. Default: (64, 96, 128).
@@ -189,7 +182,6 @@ def forward(self, x):
189
182
class InvertedBottleneck (nn .Layer ):
190
183
"""
191
184
Single Inverted bottleneck implementation.
192
-
193
185
Args:
194
186
in_channels (int): The number of input channels to bottleneck block.
195
187
out_channels (int): The number of output channels of bottleneck block.
@@ -236,9 +228,7 @@ def forward(self, x):
236
228
class FeatureFusionModule (nn .Layer ):
237
229
"""
238
230
Feature Fusion Module Implementation.
239
-
240
231
This module fuses high-resolution feature and low-resolution feature.
241
-
242
232
Args:
243
233
high_in_channels (int): The channels of high-resolution feature (output of LearningToDownsample).
244
234
low_in_channels (int): The channels of low-resolution feature (output of GlobalFeatureExtractor).
@@ -278,9 +268,7 @@ def forward(self, high_res_input, low_res_input):
278
268
class Classifier (nn .Layer ):
279
269
"""
280
270
The Classifier module implementation.
281
-
282
271
This module consists of two depth-wise conv and one conv.
283
-
284
272
Args:
285
273
input_channels (int): The input channels to this module.
286
274
num_classes (int): The unique number of target classes.
@@ -304,9 +292,11 @@ def __init__(self, input_channels, num_classes):
304
292
self .conv = nn .Conv2D (
305
293
in_channels = input_channels , out_channels = num_classes , kernel_size = 1 )
306
294
295
+ self .dropout = nn .Dropout (p = 0.1 ) # dropout_prob
296
+
307
297
def forward (self , x ):
308
298
x = self .dsconv1 (x )
309
299
x = self .dsconv2 (x )
310
- x = F .dropout (x , p = 0.1 ) # dropout_prob
300
+ x = self .dropout (x )
311
301
x = self .conv (x )
312
302
return x
0 commit comments