Exemplo n.º 1
0
    def __init__(self, in_channels, n_classes, channels=128, is_maxpool=True,is_deconv=False, is_batchnorm=True):
        super(MUNet, self).__init__()
        self.is_maxpool = is_maxpool
        self.in_channels = in_channels
        self.is_batchnorm = is_batchnorm
        self.is_deconv=is_deconv
        self.channels = channels
        self.n_classes=n_classes

        # MNET
        self.M_conv1 = unetConv2(in_channels, self.channels, self.is_batchnorm)
        self.M_up1 = nn.ConvTranspose2d(self.channels,self.channels, kernel_size=2, stride=2, padding=0)
        self.M_conv2 = unetConv2(self.channels, self.channels, self.is_batchnorm)
        self.M_up2 = nn.ConvTranspose2d(self.channels, self.channels, kernel_size=2, stride=2, padding=0)
        self.M_center = unetConv2(self.channels, self.channels, self.is_batchnorm)
        self.M_down2 = mnetDown(self.channels*2, self.channels, 2,self.is_maxpool)
        self.M_down1 = mnetDown(self.channels*2, self.channels, 2, self.is_maxpool)

        # UNET
        self.U_conv1 = unetConv2(in_channels, self.channels, self.is_batchnorm)
        self.U_down1 = nn.MaxPool2d(kernel_size=2)
        self.U_conv2 = unetConv2(self.channels, self.channels, self.is_batchnorm)
        self.U_down2 = nn.MaxPool2d(kernel_size=2)
        self.U_center = unetConv2(self.channels, self.channels, self.is_batchnorm)
        self.U_up2 = unetUp(self.channels*2, self.channels, 2, self.is_deconv)
        self.U_up1 = unetUp(self.channels*2, self.channels, 2, self.is_deconv)

        #output
        self.outconv1 = nn.Conv2d(self.channels*2, self.channels, 3, padding=1)
        self.outconv2 = nn.Conv2d(self.channels, self.n_classes, 3, padding=1)
Exemplo n.º 2
0
    def __init__(self, in_channels=1, n_classes=2, feature_scale=2, is_deconv=True, is_batchnorm=True):
        super(UNet, self).__init__()
        self.in_channels = in_channels
        self.feature_scale = feature_scale
        self.is_deconv = is_deconv
        self.is_batchnorm = is_batchnorm
        

        filters = [64, 128, 256, 512, 1024]
        filters = [int(x / self.feature_scale) for x in filters]

        # downsampling
        self.maxpool = nn.MaxPool2d(kernel_size=2)
        self.conv1 = unetConv2(self.in_channels, filters[0], self.is_batchnorm)
        self.conv2 = unetConv2(filters[0], filters[1], self.is_batchnorm)
        self.conv3 = unetConv2(filters[1], filters[2], self.is_batchnorm)
        self.conv4 = unetConv2(filters[2], filters[3], self.is_batchnorm)
        self.center = unetConv2(filters[3], filters[4], self.is_batchnorm)
        # upsampling
        self.up_concat4 = unetUp(filters[4], filters[3], self.is_deconv)
        self.up_concat3 = unetUp(filters[3], filters[2], self.is_deconv)
        self.up_concat2 = unetUp(filters[2], filters[1], self.is_deconv)
        self.up_concat1 = unetUp(filters[1], filters[0], self.is_deconv)
        # final conv (without any concat)
        self.final = nn.Conv2d(filters[0], n_classes, 1)

        # initialise weights
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                init_weights(m, init_type='kaiming')
            elif isinstance(m, nn.BatchNorm2d):
                init_weights(m, init_type='kaiming')
Exemplo n.º 3
0
    def __init__(self,
                 in_channels=3,
                 n_classes=2,
                 feature_scale=2,
                 is_deconv=True,
                 is_batchnorm=True,
                 is_ds=True):
        super(UNet_Nested, self).__init__()
        self.in_channels = in_channels
        self.feature_scale = feature_scale
        self.is_deconv = is_deconv
        self.is_batchnorm = is_batchnorm
        self.is_ds = is_ds

        filters = [64, 128, 256, 512, 1024]
        filters = [int(x / self.feature_scale) for x in filters]

        # downsampling
        self.maxpool = nn.MaxPool2d(kernel_size=2)
        self.conv00 = unetConv2(self.in_channels, filters[0],
                                self.is_batchnorm)
        self.conv10 = unetConv2(filters[0], filters[1], self.is_batchnorm)
        self.conv20 = unetConv2(filters[1], filters[2], self.is_batchnorm)
        self.conv30 = unetConv2(filters[2], filters[3], self.is_batchnorm)
        self.conv40 = unetConv2(filters[3], filters[4], self.is_batchnorm)

        # upsampling
        self.up_concat01 = unetUp(filters[1], filters[0], self.is_deconv)
        self.up_concat11 = unetUp(filters[2], filters[1], self.is_deconv)
        self.up_concat21 = unetUp(filters[3], filters[2], self.is_deconv)
        self.up_concat31 = unetUp(filters[4], filters[3], self.is_deconv)

        self.up_concat02 = unetUp(filters[1], filters[0], self.is_deconv, 3)
        self.up_concat12 = unetUp(filters[2], filters[1], self.is_deconv, 3)
        self.up_concat22 = unetUp(filters[3], filters[2], self.is_deconv, 3)

        self.up_concat03 = unetUp(filters[1], filters[0], self.is_deconv, 4)
        self.up_concat13 = unetUp(filters[2], filters[1], self.is_deconv, 4)

        self.up_concat04 = unetUp(filters[1], filters[0], self.is_deconv, 5)

        # final conv (without any concat)
        self.final_1 = nn.Conv2d(filters[0], n_classes, 1)
        self.final_2 = nn.Conv2d(filters[0], n_classes, 1)
        self.final_3 = nn.Conv2d(filters[0], n_classes, 1)
        self.final_4 = nn.Conv2d(filters[0], n_classes, 1)

        # initialise weights
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                init_weights(m, init_type='kaiming')
            elif isinstance(m, nn.BatchNorm2d):
                init_weights(m, init_type='kaiming')
Exemplo n.º 4
0
    def __init__(self, in_channels, n_classes, channels=128, is_deconv=False, is_batchnorm=True):
        super(UNet, self).__init__()
        self.is_deconv = is_deconv
        self.in_channels = in_channels
        self.is_batchnorm = is_batchnorm
        self.channels = channels
        self.n_classes=n_classes

        # downsampling
        self.conv1 = unetConv2(in_channels, self.channels, self.is_batchnorm)
        self.maxpool1 = nn.MaxPool2d(kernel_size=2)
        self.conv2 = unetConv2(self.channels, self.channels, self.is_batchnorm)
        self.maxpool2 = nn.MaxPool2d(kernel_size=2)
        self.center = unetConv2(self.channels, self.channels, self.is_batchnorm)
        # upsampling
        self.up_concat2 = unetUp(self.channels*2, self.channels, 2, self.is_deconv)
        self.up_concat1 = unetUp(self.channels*2, self.channels, 2, self.is_deconv)
        #
        self.outconv1 = nn.Conv2d(self.channels, self.n_classes, 3, padding=1)