Esempio n. 1
0
    def __init__(self, in_channels=32 + 32, out_channels=32):
        super(AgentsMapFusion, self).__init__()

        self._conv1 = conv2DBatchNormRelu(in_channels=in_channels,
                                          n_filters=out_channels,
                                          k_size=3,
                                          stride=1,
                                          padding=1,
                                          dilation=1)
        self._pool1 = nn.MaxPool2d((2, 2), stride=(2, 2))
        self._conv2 = conv2DBatchNormRelu(in_channels=out_channels,
                                          n_filters=out_channels,
                                          k_size=3,
                                          stride=1,
                                          padding=1,
                                          dilation=1)
        self._pool2 = nn.MaxPool2d((2, 2), stride=(2, 2))
        self._conv3 = conv2DBatchNormRelu(in_channels=out_channels,
                                          n_filters=out_channels,
                                          k_size=4,
                                          stride=1,
                                          padding=1,
                                          dilation=1)

        self._deconv2 = deconv2DBatchNormRelu(in_channels=out_channels,
                                              n_filters=out_channels,
                                              k_size=4,
                                              stride=2,
                                              padding=1)
Esempio n. 2
0
    def __init__(self, in_channels = 3, out_channels = 32):
        super(SemanticImageEncoder, self).__init__()

        self._encoder = nn.Sequential(
            conv2DBatchNormRelu(in_channels = in_channels, n_filters = 16, \
                k_size = 3,  stride = 1, padding = 1),
            conv2DBatchNormRelu(in_channels = 16, n_filters = 16, \
                k_size = 4,  stride = 1, padding = 2),
            nn.MaxPool2d((2, 2), stride=(2, 2)),

            conv2DBatchNormRelu(in_channels = 16, n_filters = out_channels, \
                k_size = 5,  stride = 1, padding = 2),
            )
Esempio n. 3
0
    def __init__(self):  # Output Size: 30 * 30
        super(ResnetShallow, self).__init__()

        self.trunk = torchvision.models.resnet18(pretrained=True)

        self.upscale3 = nn.Sequential(
            nn.ConvTranspose2d(256,
                               128,
                               3,
                               stride=2,
                               padding=1,
                               output_padding=1),
            nn.BatchNorm2d(128),
            nn.ReLU(inplace=True),
        )

        self.upscale4 = nn.Sequential(
            nn.ConvTranspose2d(512,
                               128,
                               7,
                               stride=4,
                               padding=3,
                               output_padding=3),
            nn.BatchNorm2d(128),
            nn.ReLU(inplace=True),
        )

        self.shrink = conv2DBatchNormRelu(in_channels=384,
                                          n_filters=32,
                                          k_size=1,
                                          stride=1,
                                          padding=0)
Esempio n. 4
0
    def __init__(self,
                 n_classes=7,
                 block_config=[3, 4, 6, 3],
                 input_size=(800, 600),
                 version=None):

        super(PSPnet, self).__init__()

        self.block_config = (pspnet_specs[version]["block_config"]
                             if version is not None else block_config)
        self.n_classes = pspnet_specs[version][
            "n_classes"] if version is not None else n_classes
        self.input_size = pspnet_specs[version][
            "input_size"] if version is not None else input_size

        # Encoder
        self.convbnrelu1_1 = conv2DBatchNormRelu(in_channels=3,
                                                 k_size=3,
                                                 n_filters=64,
                                                 padding=1,
                                                 stride=2,
                                                 bias=False)
        self.convbnrelu1_2 = conv2DBatchNormRelu(in_channels=64,
                                                 k_size=3,
                                                 n_filters=64,
                                                 padding=1,
                                                 stride=1,
                                                 bias=False)
        self.convbnrelu1_3 = conv2DBatchNormRelu(in_channels=64,
                                                 k_size=3,
                                                 n_filters=128,
                                                 padding=1,
                                                 stride=1,
                                                 bias=False)

        # Vanilla Residual Blocks
        self.res_block2 = residualBlockPSP(self.block_config[0], 128, 64, 256,
                                           1, 1)
        self.res_block3 = residualBlockPSP(self.block_config[1], 256, 128, 512,
                                           2, 1)

        # Dilated Residual Blocks
        self.res_block4 = residualBlockPSP(self.block_config[2], 512, 256,
                                           1024, 1, 2)
        self.res_block5 = residualBlockPSP(self.block_config[3], 1024, 512,
                                           2048, 1, 4)

        # Pyramid Pooling Module
        self.pyramid_pooling = pyramidPooling(2048, [6, 3, 2, 1])

        # Final conv layers
        self.cbr_final = conv2DBatchNormRelu(4096, 512, 3, 1, 1, False)
        self.dropout = nn.Dropout2d(p=0.1, inplace=False)
        self.classification = nn.Conv2d(512, self.n_classes, 1, 1, 0)

        # Auxiliary layers for training
        self.convbnrelu4_aux = conv2DBatchNormRelu(in_channels=1024,
                                                   k_size=3,
                                                   n_filters=256,
                                                   padding=1,
                                                   stride=1,
                                                   bias=False)
        self.aux_cls = nn.Conv2d(256, self.n_classes, 1, 1, 0)

        # Define auxiliary loss function
        self.loss = multi_scale_cross_entropy2d

        self.load_pretrained_model("pspnet50_ADE20K.caffemodel")
Esempio n. 5
0
    def __init__(
        self,
        n_classes=19,
        block_config=None,
        input_size=(1025, 2049),
        version=None,
        is_batchnorm=True,
    ):

        super(ICNet, self).__init__()

        self._is_batchnorm = is_batchnorm

        block_config = block_config or [3, 4, 6, 3]

        bias = not is_batchnorm

        self.block_config = (
            icnet_specs[version]["block_config"] if version is not None else block_config
        )
        self.n_classes = icnet_specs[version]["n_classes"] if version is not None else n_classes
        self.input_size = icnet_specs[version]["input_size"] if version is not None else input_size

        # Encoder
        self.convbnrelu1_1 = conv2DBatchNormRelu(
            in_channels=3,
            k_size=3,
            n_filters=32,
            padding=1,
            stride=2,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )
        self.convbnrelu1_2 = conv2DBatchNormRelu(
            in_channels=32,
            k_size=3,
            n_filters=32,
            padding=1,
            stride=1,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )
        self.convbnrelu1_3 = conv2DBatchNormRelu(
            in_channels=32,
            k_size=3,
            n_filters=64,
            padding=1,
            stride=1,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )

        # Vanilla Residual Blocks
        self.res_block2 = residualBlockPSP(
            self.block_config[0], 64, 32, 128, 1, 1, is_batchnorm=is_batchnorm
        )
        self.res_block3_conv = residualBlockPSP(
            self.block_config[1],
            128,
            64,
            256,
            2,
            1,
            include_range="conv",
            is_batchnorm=is_batchnorm,
        )
        self.res_block3_identity = residualBlockPSP(
            self.block_config[1],
            128,
            64,
            256,
            2,
            1,
            include_range="identity",
            is_batchnorm=is_batchnorm,
        )

        # Dilated Residual Blocks
        self.res_block4 = residualBlockPSP(
            self.block_config[2], 256, 128, 512, 1, 2, is_batchnorm=is_batchnorm
        )
        self.res_block5 = residualBlockPSP(
            self.block_config[3], 512, 256, 1024, 1, 4, is_batchnorm=is_batchnorm
        )

        # Pyramid Pooling Module
        self.pyramid_pooling = pyramidPooling(
            1024, [6, 3, 2, 1], model_name="icnet", fusion_mode="sum", is_batchnorm=is_batchnorm
        )

        # Final conv layer with kernel 1 in sub4 branch
        self.conv5_4_k1 = conv2DBatchNormRelu(
            in_channels=1024,
            k_size=1,
            n_filters=256,
            padding=0,
            stride=1,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )

        # High-resolution (sub1) branch
        self.convbnrelu1_sub1 = conv2DBatchNormRelu(
            in_channels=3,
            k_size=3,
            n_filters=32,
            padding=1,
            stride=2,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )
        self.convbnrelu2_sub1 = conv2DBatchNormRelu(
            in_channels=32,
            k_size=3,
            n_filters=32,
            padding=1,
            stride=2,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )
        self.convbnrelu3_sub1 = conv2DBatchNormRelu(
            in_channels=32,
            k_size=3,
            n_filters=64,
            padding=1,
            stride=2,
            bias=bias,
            is_batchnorm=is_batchnorm,
        )
        self.classification = nn.Conv2d(128, self.n_classes, 1, 1, 0)

        # Cascade Feature Fusion Units
        self.cff_sub24 = cascadeFeatureFusion(
            self.n_classes, 256, 256, 128, is_batchnorm=is_batchnorm
        )
        self.cff_sub12 = cascadeFeatureFusion(
            self.n_classes, 128, 64, 128, is_batchnorm=is_batchnorm
        )