def _aspp(self, x, out_filters): xs = list() x1 = layers.Conv2D(out_filters, 1, strides=1)(x) xs.append(x1) for i in range(3): xi = layers.Conv2D(out_filters, 3, strides=1, padding='same', dilation_rate=6 * (i + 1))(x) xs.append(xi) img_pool = custom_layers.GlobalAveragePooling2D(keep_dims=True)(x) img_pool = layers.Conv2D(out_filters, 1, 1, kernel_initializer='he_normal')(img_pool) img_pool = layers.UpSampling2D(size=self.aspp_size, interpolation='bilinear')(img_pool) xs.append(img_pool) x = custom_layers.Concatenate(out_size=self.aspp_size)(xs) x = layers.Conv2D(out_filters, 1, strides=1, kernel_initializer='he_normal')(x) x = layers.BatchNormalization()(x) return x
def _deeplab_v3_plus(self, inputs): num_classes = self.num_classes _, h, w, _ = backend.int_shape(inputs) self.aspp_size = (h // 16, w // 16) if self.base_model in [ 'VGG16', 'VGG19', 'ResNet50', 'ResNet101', 'ResNet152', 'MobileNetV1', 'MobileNetV2' ]: c2, c5 = self.encoder(inputs, output_stages=['c2', 'c5']) else: c2, c5 = self.encoder(inputs, output_stages=['c1', 'c5']) x = self._aspp(c5, 256) x = layers.Dropout(rate=0.5)(x) x = layers.UpSampling2D(size=(4, 4), interpolation='bilinear')(x) x = self._conv_bn_relu(x, 48, 1, strides=1) x = custom_layers.Concatenate(out_size=self.aspp_size)([x, c2]) x = self._conv_bn_relu(x, 256, 3, 1) x = layers.Dropout(rate=0.5)(x) x = self._conv_bn_relu(x, 256, 3, 1) x = layers.Dropout(rate=0.1)(x) x = layers.Conv2D(num_classes, 1, strides=1)(x) x = layers.UpSampling2D(size=(4, 4), interpolation='bilinear')(x) outputs = x return models.Model(inputs, outputs, name=self.version)
def _denseaspp(self, inputs): _, inputs_h, inputs_w, _ = backend.int_shape(inputs) aspp_size = inputs_h // 8, inputs_w // 8 num_classes = self.num_classes c5 = self.encoder(inputs, output_stages='c5') # First block rate=3 d3 = self._dilated_conv_block(c5, 256, 1) d3 = self._dilated_conv_block(d3, 64, 3, rate=3) # Second block rate=6 d4 = custom_layers.Concatenate(out_size=aspp_size)([c5, d3]) d4 = self._dilated_conv_block(d4, 256, 1) d4 = self._dilated_conv_block(d4, 64, 3, rate=6) # Third block rate=12 d5 = custom_layers.Concatenate(out_size=aspp_size)([c5, d3, d4]) d5 = self._dilated_conv_block(d5, 256, 1) d5 = self._dilated_conv_block(d5, 64, 3, rate=12) # Forth block rate=18 d6 = custom_layers.Concatenate(out_size=aspp_size)([c5, d3, d4, d5]) d6 = self._dilated_conv_block(d6, 256, 1) d6 = self._dilated_conv_block(d6, 64, 3, rate=18) # Fifth block rate=24 d7 = custom_layers.Concatenate(out_size=aspp_size)( [c5, d3, d4, d5, d6]) d7 = self._dilated_conv_block(d7, 256, 1) d7 = self._dilated_conv_block(d7, 64, 3, rate=24) x = custom_layers.Concatenate(out_size=aspp_size)( [c5, d3, d4, d5, d6, d7]) x = layers.Conv2D(num_classes, 1, strides=1, kernel_initializer='he_normal')(x) x = layers.UpSampling2D(size=(8, 8), interpolation='bilinear')(x) outputs = x return models.Model(inputs, outputs, name=self.version)