コード例 #1
0
ファイル: dense.py プロジェクト: zx991201/torch-points3d
 def __init__(self,
              npoint=None,
              radii=None,
              nsample=None,
              down_conv_nn=None,
              bn=True,
              activation=torch.nn.LeakyReLU(negative_slope=0.01),
              use_xyz=True,
              normalize_xyz=False,
              **kwargs):
     assert len(radii) == len(nsample) == len(down_conv_nn)
     super(PointNetMSGDown,
           self).__init__(DenseFPSSampler(num_to_sample=npoint),
                          DenseRadiusNeighbourFinder(radii, nsample),
                          **kwargs)
     self.use_xyz = use_xyz
     self.npoint = npoint
     self.mlps = nn.ModuleList()
     for i in range(len(radii)):
         self.mlps.append(
             MLP2D(down_conv_nn[i],
                   bn=bn,
                   activation=activation,
                   bias=False))
     self.radii = radii
     self.normalize_xyz = normalize_xyz
コード例 #2
0
    def __init__(self,
                 npoint=None,
                 radii=None,
                 nsample=None,
                 down_conv_nn=None,
                 channel_raising_nn=None,
                 bn=True,
                 bias=True,
                 use_xyz=True,
                 activation=nn.ReLU(),
                 **kwargs):
        assert len(radii) == len(nsample)
        if len(radii) != len(down_conv_nn):
            log.warning(
                "The down_conv_nn has a different size as radii. Make sure to have sharedMLP"
            )
        super(RSConvMSGDown,
              self).__init__(DenseFPSSampler(num_to_sample=npoint),
                             DenseRadiusNeighbourFinder(radii, nsample),
                             **kwargs)

        self.use_xyz = use_xyz
        self.npoint = npoint
        self.mlps = nn.ModuleList()

        # https://github.com/Yochengliu/Relation-Shape-CNN/blob/6464eb8bb4efc686adec9da437112ef888e55684/utils/pointnet2_modules.py#L106

        self.mlp_out = Seq(*[
            Conv1d(channel_raising_nn[0],
                   channel_raising_nn[-1],
                   kernel_size=1,
                   stride=1,
                   bias=True),
            nn.BatchNorm1d(channel_raising_nn[-1]),
            activation,
        ])

        for i in range(len(radii)):
            mapper = RSConvMapper(down_conv_nn,
                                  activation=activation,
                                  use_xyz=self.use_xyz)
            self.mlps.append(SharedRSConv(mapper, radii[i]))

        self._mapper = mapper
コード例 #3
0
 def __init__(self,
              npoint=None,
              radii=None,
              nsample=None,
              down_conv_nn=None,
              bn=True,
              activation="LeakyReLU",
              use_xyz=True,
              **kwargs):
     assert len(radii) == len(nsample) == len(down_conv_nn)
     super(PointNetMSGDown,
           self).__init__(DenseFPSSampler(num_to_sample=npoint),
                          DenseRadiusNeighbourFinder(radii, nsample),
                          **kwargs)
     self.use_xyz = use_xyz
     self.npoint = npoint
     self.mlps = nn.ModuleList()
     for i in range(len(radii)):
         self.mlps.append(
             pt_utils.SharedMLP(down_conv_nn[i],
                                bn=bn,
                                activation=get_activation(activation)))
コード例 #4
0
    def __init__(
        self,
        npoint=None,
        radii=None,
        nsample=None,
        down_conv_nn=None,
        channel_raising_nn=None,
        bn=True,
        bias=True,
        use_xyz=True,
        activation=nn.ReLU(),
        **kwargs
    ):
        assert len(radii) == len(nsample)
        if len(radii) != len(down_conv_nn):
            log.warning("The down_conv_nn has a different size as radii. Make sure of have SharedRSConv")
        super(RSConvOriginalMSGDown, self).__init__(
            DenseFPSSampler(num_to_sample=npoint), DenseRadiusNeighbourFinder(radii, nsample), **kwargs
        )

        self.use_xyz = use_xyz
        self.mlps = nn.ModuleList()
        self.mappings = nn.ModuleList()

        self._first_layer = True if len(down_conv_nn) == 2 else False

        if self._first_layer:
            C_in, C_intermediate, C_out = down_conv_nn[0]
            feat_in, f_out = down_conv_nn[-1]
            xyz_raising = nn.Conv2d(
                in_channels=feat_in, out_channels=f_out, kernel_size=(1, 1), stride=(1, 1), bias=bias,
            )
            nn.init.kaiming_normal_(xyz_raising.weight)
            if bias:
                nn.init.constant_(xyz_raising.bias, 0)
        else:
            C_in, C_intermediate, C_out = down_conv_nn

        mapping_func1 = nn.Conv2d(
            in_channels=C_in, out_channels=C_intermediate, kernel_size=(1, 1), stride=(1, 1), bias=bias,
        )
        mapping_func2 = nn.Conv2d(
            in_channels=C_intermediate, out_channels=C_out, kernel_size=(1, 1), stride=(1, 1), bias=bias,
        )

        nn.init.kaiming_normal_(mapping_func1.weight)
        nn.init.kaiming_normal_(mapping_func2.weight)
        if bias:
            nn.init.constant_(mapping_func1.bias, 0)
            nn.init.constant_(mapping_func2.bias, 0)

        # channel raising mapping
        cr_mapping = nn.Conv1d(
            in_channels=channel_raising_nn[0], out_channels=channel_raising_nn[1], kernel_size=1, stride=1, bias=bias,
        )
        nn.init.kaiming_normal_(cr_mapping.weight)
        nn.init.constant_(cr_mapping.bias, 0)

        if self._first_layer:
            mapping = [mapping_func1, mapping_func2, cr_mapping, xyz_raising]
        elif npoint is not None:
            mapping = [mapping_func1, mapping_func2, cr_mapping]

        for m in mapping:
            self.mappings.append(m)

        for radius in radii:
            self.mlps.append(OriginalRSConv(mapping=mapping, first_layer=self._first_layer, radius=radius))