def network_initialization(
        self, in_channel, out_channel, channels, embedding_channel, kernel_size, D=2,
    ):
        self.conv1_1 = self.get_conv_block(in_channel, channels[0], kernel_size=kernel_size, stride=1)
        self.conv1_2 = self.get_conv_block(channels[0], channels[1], kernel_size=kernel_size, stride=1)
        self.pool1 = ME.MinkowskiMaxPooling(kernel_size=3, stride=2, dimension=D)

        self.conv2_1 = self.get_conv_block(channels[1], channels[2], kernel_size=kernel_size, stride=1)
        self.conv2_2 = self.get_conv_block(channels[2], channels[3], kernel_size=kernel_size, stride=1)
        self.pool2 = ME.MinkowskiMaxPooling(kernel_size=3, stride=2, dimension=D)

        self.conv3_1 = self.get_conv_block(channels[3], channels[4], kernel_size=kernel_size, stride=1)
        self.conv3_2 = self.get_conv_block(channels[4], channels[5], kernel_size=kernel_size, stride=1)
        self.conv3_3 = self.get_conv_block(channels[5], channels[6], kernel_size=kernel_size, stride=1)
        self.pool3 = ME.MinkowskiMaxPooling(kernel_size=3, stride=2, dimension=D)

        self.conv4_1 = self.get_conv_block(channels[6], channels[7], kernel_size=kernel_size, stride=1)
        self.conv4_2 = self.get_conv_block(channels[7], channels[8], kernel_size=kernel_size, stride=1)
        self.conv4_3 = self.get_conv_block(channels[8], channels[9], kernel_size=kernel_size, stride=1)
        self.pool4 = ME.MinkowskiMaxPooling(kernel_size=3, stride=2, dimension=D)

        self.conv5_1 = self.get_conv_block(channels[9], channels[10], kernel_size=kernel_size, stride=1)
        self.conv5_2 = self.get_conv_block(channels[10], channels[11], kernel_size=kernel_size, stride=1)
        self.conv5_3 = self.get_conv_block(channels[11], channels[12], kernel_size=kernel_size, stride=1)
        self.pool5 = ME.MinkowskiMaxPooling(kernel_size=3, stride=2, dimension=D)

        self.global_pool = ME.MinkowskiGlobalPooling()

        self.final = nn.Sequential(
            self.get_mlp_block(512, 512),
            ME.MinkowskiDropout(),
            self.get_mlp_block(512, 512),
            self.get_mlp_block(512, 2),
            #ME.MinkowskiFunctional.softmax(),
        )
Exemplo n.º 2
0
 def __init__(self,
              en_ch=[3, 64, 128, 256],
              de_ch=[256, 128, 32, 1],
              D=3,
              lang_feat_dim=256):
     super().__init__()
     self.en1 = nn.Sequential(
         ME.MinkowskiConvolution(en_ch[0],
                                 en_ch[1],
                                 kernel_size=3,
                                 dimension=D),
         ME.MinkowskiReLU(inplace=True),
         ME.MinkowskiMaxPooling(kernel_size=2, stride=2, dimension=D))  # 15
     self.en2 = nn.Sequential(
         ME.MinkowskiConvolution(en_ch[1],
                                 en_ch[2],
                                 kernel_size=3,
                                 dimension=D),
         ME.MinkowskiReLU(inplace=True),
         ME.MinkowskiMaxPooling(kernel_size=2, stride=2, dimension=D))
     self.en3 = nn.Sequential(
         ME.MinkowskiConvolution(en_ch[2],
                                 en_ch[3],
                                 kernel_size=3,
                                 dimension=D),
         ME.MinkowskiReLU(inplace=True),
         ME.MinkowskiMaxPooling(kernel_size=2, stride=2, dimension=D))
     self.fuse_layer = nn.Sequential(
         ME.MinkowskiConvolution(en_ch[3] + lang_feat_dim,
                                 en_ch[3] + lang_feat_dim,
                                 kernel_size=1,
                                 dimension=D),
         ME.MinkowskiReLU(inplace=True),
         ME.MinkowskiConvolution(en_ch[3] + lang_feat_dim,
                                 en_ch[3] + lang_feat_dim // 2,
                                 kernel_size=1,
                                 dimension=D),
         ME.MinkowskiReLU(inplace=True),
         ME.MinkowskiConvolution(en_ch[3] + lang_feat_dim // 2,
                                 en_ch[3],
                                 kernel_size=1,
                                 dimension=D),
         ME.MinkowskiReLU(inplace=True))
     self.de3 = upblock(down_channels=en_ch[3],
                        skip_channels=en_ch[2],
                        out_channels=de_ch[0])
     self.de2 = upblock(down_channels=de_ch[0],
                        skip_channels=en_ch[1],
                        out_channels=de_ch[1])
     self.de1 = upblock(down_channels=de_ch[1],
                        skip_channels=en_ch[0],
                        out_channels=de_ch[2])
     self.final_layer = nn.Sequential(
         ME.MinkowskiConvolution(de_ch[2],
                                 de_ch[3],
                                 kernel_size=1,
                                 dimension=D), )
Exemplo n.º 3
0
    def network_initialization(self, in_channels, out_channels, D):
        self.conv1 = ME.MinkowskiConvolution(in_channels,
                                             8,
                                             kernel_size=3,
                                             dimension=D)
        self.conv2 = ME.MinkowskiConvolution(8, 8, kernel_size=3, dimension=D)

        self.pool = ME.MinkowskiMaxPooling(kernel_size=3,
                                           stride=2,
                                           dimension=D)

        self.conv3 = ME.MinkowskiConvolution(8, 16, kernel_size=3, dimension=D)
        self.conv4 = ME.MinkowskiConvolution(16,
                                             16,
                                             kernel_size=3,
                                             dimension=D)
Exemplo n.º 4
0
    def network_initialization(self, in_channels, out_channels, D):

        self.inplanes = self.INIT_DIM
        self.conv1 = nn.Sequential(
            ME.MinkowskiConvolution(in_channels,
                                    self.inplanes,
                                    kernel_size=3,
                                    stride=2,
                                    dimension=D),
            ME.MinkowskiBatchNorm(self.inplanes),
            ME.MinkowskiReLU(inplace=True),
            ME.MinkowskiMaxPooling(kernel_size=2, stride=2, dimension=D),
        )

        self.layer1 = self._make_layer(self.BLOCK,
                                       self.PLANES[0],
                                       self.LAYERS[0],
                                       stride=2)
        self.layer2 = self._make_layer(self.BLOCK,
                                       self.PLANES[1],
                                       self.LAYERS[1],
                                       stride=2)
        self.layer3 = self._make_layer(self.BLOCK,
                                       self.PLANES[2],
                                       self.LAYERS[2],
                                       stride=2)
        self.layer4 = self._make_layer(self.BLOCK,
                                       self.PLANES[3],
                                       self.LAYERS[3],
                                       stride=2)

        self.conv5 = nn.Sequential(
            ME.MinkowskiDropout(),
            ME.MinkowskiConvolution(self.inplanes,
                                    self.inplanes,
                                    kernel_size=3,
                                    stride=3,
                                    dimension=D),
            ME.MinkowskiBatchNorm(self.inplanes),
            ME.MinkowskiGELU(),
        )

        self.glob_pool = ME.MinkowskiGlobalMaxPooling()

        self.final = ME.MinkowskiLinear(self.inplanes, out_channels, bias=True)
Exemplo n.º 5
0
    def network_initialization(
        self, in_channel, out_channel, channels, embedding_channel, kernel_size, D=3,
    ):
        self.mlp1 = self.get_mlp_block(in_channel, channels[0])
        self.conv1 = self.get_conv_block(
            channels[0], channels[1], kernel_size=kernel_size, stride=1,
        )
        self.conv2 = self.get_conv_block(
            channels[1], channels[2], kernel_size=kernel_size, stride=2,
        )

        self.conv3 = self.get_conv_block(
            channels[2], channels[3], kernel_size=kernel_size, stride=2,
        )

        self.conv4 = self.get_conv_block(
            channels[3], channels[4], kernel_size=kernel_size, stride=2,
        )
        self.conv5 = nn.Sequential(
            self.get_conv_block(
                channels[1] + channels[2] + channels[3] + channels[4],
                embedding_channel // 4,
                kernel_size=3,
                stride=2,
            ),
            self.get_conv_block(
                embedding_channel // 4, embedding_channel // 2, kernel_size=3, stride=2,
            ),
            self.get_conv_block(
                embedding_channel // 2, embedding_channel, kernel_size=3, stride=2,
            ),
        )

        self.pool = ME.MinkowskiMaxPooling(kernel_size=3, stride=2, dimension=D)

        self.global_max_pool = ME.MinkowskiGlobalMaxPooling()
        self.global_avg_pool = ME.MinkowskiGlobalAvgPooling()

        self.final = nn.Sequential(
            self.get_mlp_block(embedding_channel * 2, 512),
            ME.MinkowskiDropout(),
            self.get_mlp_block(512, 512),
            ME.MinkowskiLinear(512, out_channel, bias=True),
        )
Exemplo n.º 6
0
def max_pool(kernel_size,
             stride=1,
             dilation=1,
             conv_type=ConvType.HYPERCUBE,
             in_coords_key=None,
             D=-1):
    assert D > 0, 'Dimension must be a positive integer'
    region_type, axis_types, kernel_size = convert_conv_type(
        conv_type, kernel_size, D)
    kernel_generator = ME.KernelGenerator(kernel_size,
                                          stride,
                                          dilation,
                                          region_type=region_type,
                                          axis_types=axis_types,
                                          dimension=D)

    return ME.MinkowskiMaxPooling(kernel_size=kernel_size,
                                  stride=stride,
                                  dilation=dilation,
                                  kernel_generator=kernel_generator,
                                  dimension=D)
Exemplo n.º 7
0
    def __init__(self,
                 in_planes,
                 out_planes,
                 kernel_size,
                 stride,
                 with_uncertainty=False,
                 add_rgb=False):
        super().__init__()
        self.layer3 = nn.Sequential(
            ME.MinkowskiConvolution(in_planes,
                                    out_planes * 2,
                                    kernel_size=kernel_size,
                                    stride=1,
                                    dimension=2),
            ME.MinkowskiBatchNorm(out_planes * 2),
            ME.MinkowskiReLU(inplace=True),
            ME.MinkowskiConvolution(out_planes * 2,
                                    out_planes * 2,
                                    kernel_size=kernel_size,
                                    stride=1,
                                    dimension=2),
            ME.MinkowskiBatchNorm(out_planes * 2),
            ME.MinkowskiReLU(inplace=True),
            ME.MinkowskiConvolution(out_planes * 2,
                                    out_planes,
                                    kernel_size=kernel_size,
                                    stride=1,
                                    dimension=2),
        )

        self.layer2 = nn.Sequential(
            ME.MinkowskiConvolution(in_planes,
                                    out_planes * 2,
                                    kernel_size=kernel_size,
                                    stride=1,
                                    dimension=2),
            ME.MinkowskiBatchNorm(out_planes * 2),
            ME.MinkowskiReLU(inplace=True),
            ME.MinkowskiConvolution(out_planes * 2,
                                    out_planes,
                                    kernel_size=kernel_size,
                                    stride=1,
                                    dimension=2),
        )

        self.layer1 = nn.Sequential(
            ME.MinkowskiConvolution(in_planes,
                                    out_planes,
                                    kernel_size=kernel_size,
                                    stride=1,
                                    dimension=2), )

        self.layer_final = nn.Sequential(ME.MinkowskiBatchNorm(out_planes),
                                         ME.MinkowskiReLU(inplace=True))
        self.pool = None if stride == 1 else ME.MinkowskiMaxPooling(
            3, stride, dimension=2)

        self.add_rgb = add_rgb
        self.with_uncertainty = with_uncertainty
        if with_uncertainty:
            self.unc_layer = nn.Sequential(
                ME.MinkowskiConvolution(out_planes,
                                        1,
                                        kernel_size=3,
                                        stride=1,
                                        dimension=2), ME.MinkowskiSigmoid())
Exemplo n.º 8
0
# coords = torch.rand([N_voxel])*10
# coords = torch.cat([torch.zeros(N_voxel,1), coords], dim=1)

coords = torch.tensor([[0, 2., 4., 2.],
                       [0, 1., 3., 1.],
                       # [0, 0., 3., 1.]
                       [0, 4., 6., 3.]
                       # [0, 1., 5., 1.]
                       ])

conv1 = ME.MinkowskiConvolution(1,1,kernel_size=1,dimension=3)
convt1 = ME.MinkowskiConvolutionTranspose(1,1,kernel_size=1,dimension=3)
conv2 = nn.Conv2d(1,1,kernel_size=1,bias=False)

conv_s2 = ME.MinkowskiConvolution(1,1,kernel_size=2,stride=2,dimension=3)
pool_s2 = ME.MinkowskiMaxPooling(2,stride=2,dimension=3)

for n, m in conv1.named_parameters():
    print(n,m)

conv2.weight = nn.Parameter(m.reshape(1,1,1,1))

x1 = ME.SparseTensor(coordinates=coords, features=feats.reshape([-1,1]))\

y1 = conv1(x1)
y1t = convt1(x1) # different weight, but they are equal

x2 = ME.SparseTensor(coordinates=coords, features=feats2.reshape([-1,1]))

x1_s2 = conv_s2(x1)
x1_p2 = pool_s2(x1)