def __init__(self, args, num_classes): """ Initializes Deeplabv3_plus Args: args (argparse.ArgumentParser): command line arguments num_classes (int): specifies the output channels of the last convolution """ super(Deeplabv3_plus, self).__init__() self.args = args if args.model == DEEPLAB: self.backbone = ResNet101(args.output_stride, args.init_type) if self.args.refine_network: self.refine_backbone = ResNet101(args.output_stride, args.init_type) elif args.model == DEEPLAB_50: self.backbone = ResNet50(args.output_stride, args.init_type) if self.args.refine_network: self.refine_backbone = ResNet50(args.output_stride, args.init_type) else: raise NotImplementedError() self.aspp = ASPP(args.output_stride, self.args.resize) self.decoder = Decoder(num_classes) self.upsampling = tf.keras.layers.UpSampling2D((4,4), interpolation='bilinear') if self.args.refine_network: self.refine_aspp = ASPP(args.output_stride, self.args.resize) self.refine_decoder = Decoder(num_classes)
def __init__(self): super(SSD, self).__init__() self.num_classes = NUM_CLASSES self.anchor_ratios = ASPECT_RATIOS self.backbone = ResNet50() self.learnable_factor = self.add_weight( shape=(1, 1, 1, 512), dtype=tf.float32, initializer=tf.keras.initializers.Ones(), trainable=True, name='fckr') # self.conv1 = tf.keras.layers.Conv2D(filters=1024, kernel_size=(1, 1), strides=1, padding="same") self.conv2_1 = tf.keras.layers.Conv2D(filters=256, kernel_size=(1, 1), strides=1, padding="same") self.conv2_2 = tf.keras.layers.Conv2D(filters=512, kernel_size=(3, 3), strides=2, padding="same") self.conv3_1 = tf.keras.layers.Conv2D(filters=128, kernel_size=(1, 1), strides=1, padding="same") self.conv3_2 = tf.keras.layers.Conv2D(filters=256, kernel_size=(3, 3), strides=2, padding="same") self.conv4_1 = tf.keras.layers.Conv2D(filters=128, kernel_size=(1, 1), strides=1, padding="same") self.conv4_2 = tf.keras.layers.Conv2D(filters=256, kernel_size=(3, 3), strides=2, padding="same") self.pool = tf.keras.layers.GlobalAveragePooling2D() self.predict_1 = self._predict_layer(k=self._get_k(i=0)) self.predict_2 = self._predict_layer(k=self._get_k(i=1)) self.predict_3 = self._predict_layer(k=self._get_k(i=2)) self.predict_4 = self._predict_layer(k=self._get_k(i=3)) self.predict_5 = self._predict_layer(k=self._get_k(i=4)) self.predict_6 = self._predict_layer(k=self._get_k(i=5))
def __init__(self): super(SSD, self).__init__() self.num_classes = NUM_CLASSES + 1 self.anchor_ratios = ASPECT_RATIOS self.backbone = ResNet50() self.conv1 = tf.keras.layers.Conv2D(filters=1024, kernel_size=(1, 1), strides=1, padding="same") self.conv2_1 = tf.keras.layers.Conv2D(filters=256, kernel_size=(1, 1), strides=1, padding="same") self.conv2_2 = tf.keras.layers.Conv2D(filters=512, kernel_size=(3, 3), strides=2, padding="same") self.conv3_1 = tf.keras.layers.Conv2D(filters=128, kernel_size=(1, 1), strides=1, padding="same") self.conv3_2 = tf.keras.layers.Conv2D(filters=256, kernel_size=(3, 3), strides=2, padding="same") self.conv4_1 = tf.keras.layers.Conv2D(filters=128, kernel_size=(1, 1), strides=1, padding="same") self.conv4_2 = tf.keras.layers.Conv2D(filters=256, kernel_size=(3, 3), strides=2, padding="same") self.pool = tf.keras.layers.GlobalAveragePooling2D() self.predict_1 = self._predict_layer(k=self._get_k(i=0)) self.predict_2 = self._predict_layer(k=self._get_k(i=1)) self.predict_3 = self._predict_layer(k=self._get_k(i=2)) self.predict_4 = self._predict_layer(k=self._get_k(i=3)) self.predict_5 = self._predict_layer(k=self._get_k(i=4)) self.predict_6 = self._predict_layer(k=self._get_k(i=5))
def __init__(self, args, num_classes=21, norm_layer=nn.BatchNorm2d, input_channels=3): super(DeepLabv3_plus, self).__init__() self.args = args if args.model == DEEPLAB: self.backbone = ResNet101(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained, input_channels=input_channels) self.aspp_inplanes = 2048 self.decoder_inplanes = 256 if self.args.refine_network: self.refine_backbone = ResNet101(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained, input_channels=input_channels + num_classes) elif args.model == DEEPLAB_50: self.backbone = ResNet50(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained) self.aspp_inplanes = 2048 self.decoder_inplanes = 256 if self.args.refine_network: self.refine_backbone = ResNet50(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained, input_channels=input_channels + num_classes) elif args.model == DEEPLAB_34: self.backbone = ResNet34(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained) self.aspp_inplanes = 2048 self.decoder_inplanes = 256 if self.args.refine_network: self.refine_backbone = ResNet34(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained, input_channels=input_channels + num_classes) elif args.model == DEEPLAB_18: self.backbone = ResNet18(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained) self.aspp_inplanes = 2048 self.decoder_inplanes = 256 if self.args.refine_network: self.refine_backbone = ResNet18(args.output_stride, norm_layer=norm_layer, pretrained=args.pretrained, input_channels=input_channels + num_classes) elif args.model == DEEPLAB_MOBILENET: self.backbone = MobileNet_v2(pretrained=args.pretrained, first_layer_input_channels=input_channels) self.aspp_inplanes = 320 self.decoder_inplanes = 24 if self.args.refine_network: self.refine_backbone = MobileNet_v2(pretrained=args.pretrained, first_layer_input_channels=input_channels + num_classes) elif args.model == DEEPLAB_MOBILENET_DILATION: self.backbone = MobileNet_v2_dilation(pretrained=args.pretrained, first_layer_input_channels=input_channels) self.aspp_inplanes = 320 if self.args.refine_network: self.refine_backbone = MobileNet_v2_dilation(pretrained=args.pretrained, first_layer_input_channels=input_channels + num_classes) self.decoder_inplanes = 24 else: raise NotImplementedError if self.args.use_aspp: self.aspp = ASPP(args.output_stride, norm_layer=norm_layer, inplanes=self.aspp_inplanes) aspp_outplanes = 256 if self.args.use_aspp else self.aspp_inplanes self.decoder = Decoder(num_classes, norm_layer=norm_layer, inplanes=self.decoder_inplanes, aspp_outplanes=aspp_outplanes) if self.args.learned_upsampling: self.learned_upsampling = nn.Sequential(nn.ConvTranspose2d(num_classes, num_classes, kernel_size=4, stride=2, padding=1), nn.ConvTranspose2d(num_classes, num_classes, kernel_size=4, stride=2, padding=1)) if self.args.refine_network: if self.args.use_aspp: self.refine_aspp = ASPP(args.output_stride, norm_layer=norm_layer, inplanes=self.aspp_inplanes) self.refine_decoder = Decoder(num_classes, norm_layer=norm_layer, inplanes=self.decoder_inplanes, aspp_outplanes=aspp_outplanes) if self.args.learned_upsampling: self.refine_learned_upsampling = nn.Sequential(nn.ConvTranspose2d(num_classes, num_classes, kernel_size=4, stride=2, padding=1), nn.ConvTranspose2d(num_classes, num_classes, kernel_size=4, stride=2, padding=1))