def __init__(self,
                 *,
                 mlps: List[List[int]],
                 radii: List[float],
                 nsamples: List[int],
                 post_mlp: List[int],
                 bn: bool = True,
                 use_xyz: bool = True,
                 sample_uniformly: bool = False):
        super().__init__()

        assert (len(mlps) == len(nsamples) == len(radii))

        self.post_mlp = pt_utils.SharedMLP(post_mlp, bn=bn)

        self.groupers = nn.ModuleList()
        self.mlps = nn.ModuleList()
        for i in range(len(radii)):
            radius = radii[i]
            nsample = nsamples[i]
            self.groupers.append(
                pointnet2_utils.QueryAndGroup(
                    radius,
                    nsample,
                    use_xyz=use_xyz,
                    sample_uniformly=sample_uniformly))
            mlp_spec = mlps[i]
            if use_xyz:
                mlp_spec[0] += 3

            self.mlps.append(pt_utils.SharedMLP(mlp_spec, bn=bn))
Esempio n. 2
0
    def __init__(self,
                 npoint=1024,
                 up_ratio=2,
                 use_normal=False,
                 use_bn=False,
                 use_res=False):
        super().__init__()

        self.npoint = npoint
        self.use_normal = use_normal
        self.up_ratio = up_ratio

        mlps = [64, 128, 256, 1024]
        fc_mlps = [1024, 512, 64, 3]

        ## for feature extraciton
        in_ch = 3 if not use_normal else 6
        self.SA_layer = pt_utils.SharedMLP([in_ch] + mlps, bn=use_bn)

        ## feature Expansion
        in_ch = mlps[-1] + 3  # fp output + input xyz
        self.FC_Modules = nn.ModuleList()
        for k in range(up_ratio):
            self.FC_Modules.append(
                pt_utils.SharedMLP([in_ch, 256, 128], bn=use_bn))

        ## coordinate reconstruction
        in_ch = 128
        self.pcd_layer = nn.Sequential(
            pt_utils.SharedMLP([in_ch, 64], bn=use_bn),
            pt_utils.SharedMLP([64, 3], activation=None, bn=False))
Esempio n. 3
0
    def __init__(self,
                 npoint=1024,
                 up_ratio=2,
                 use_normal=False,
                 use_bn=False,
                 use_res=False):
        super().__init__()

        self.npoint = npoint
        self.use_normal = use_normal
        self.up_ratio = up_ratio

        self.npoints = [npoint, npoint // 2, npoint // 4, npoint // 8]

        mlps = [[32, 32, 64], [64, 64, 128], [128, 128, 256], [256, 256, 512]]

        radius = [0.05, 0.1, 0.2, 0.3]

        nsamples = [32, 32, 32, 32]

        ## for 4 downsample layers
        in_ch = 0 if not use_normal else 3
        self.SA_modules = nn.ModuleList()
        for k in range(len(self.npoints)):
            self.SA_modules.append(
                PointnetSAModule(npoint=self.npoints[k],
                                 radius=radius[k],
                                 nsample=nsamples[k],
                                 mlp=[in_ch] + mlps[k],
                                 use_xyz=True,
                                 use_res=use_res,
                                 bn=use_bn))
            in_ch = mlps[k][-1]

        ## upsamples for layer 2 ~ 4
        self.FP_Modules = nn.ModuleList()
        for k in range(len(self.npoints) - 1):
            self.FP_Modules.append(
                PointnetFPModule(mlp=[mlps[k + 1][-1] + 64, 64], bn=use_bn))

        ## feature Expansion
        in_ch = len(self.npoints) * 64 + 3  # 4 layers + input xyz
        self.FC_Modules = nn.ModuleList()
        for k in range(up_ratio):
            self.FC_Modules.append(
                pt_utils.SharedMLP([in_ch, 256, 128], bn=use_bn))

        ## coordinate reconstruction
        in_ch = 128
        self.pcd_layer = nn.Sequential(
            pt_utils.SharedMLP([in_ch, 64], bn=use_bn),
            pt_utils.SharedMLP([64, 3], activation=None, bn=False))
Esempio n. 4
0
    def __init__(self, *, npoint: int, radii: List[float], nsamples: List[int], mlps: List[List[int]], bn: bool = True,
                 use_xyz: bool = True, pool_method='max_pool', instance_norm=False):
        """
        :param npoint: int
        :param radii: list of float, list of radii to group with
        :param nsamples: list of int, number of samples in each ball query
        :param mlps: list of list of int, spec of the pointnet before the global pooling for each scale
        :param bn: whether to use batchnorm
        :param use_xyz:
        :param pool_method: max_pool / avg_pool
        :param instance_norm: whether to use instance_norm
        """
        super().__init__()

        assert len(radii) == len(nsamples) == len(mlps)

        self.npoint = npoint
        self.groupers = nn.ModuleList()
        self.mlps = nn.ModuleList()
        for i in range(len(radii)):
            radius = radii[i]
            nsample = nsamples[i]
            self.groupers.append(
                hpcnet_utils.HPC_Group(radius, nsample, use_xyz=use_xyz)
                if npoint is not None else pointnet2_utils.GroupAll(use_xyz)
            )
            mlp_spec = mlps[i]
            mlp_spec[0] += 42
            if use_xyz:
                mlp_spec[0] += 3

            self.mlps.append(pt_utils.SharedMLP(mlp_spec, bn=bn, instance_norm=instance_norm))
        self.pool_method = pool_method
    def __init__(self,
                 *,
                 npoint: int,
                 radii: List[float],
                 nsamples: List[int],
                 mlps: List[List[int]],
                 bn: bool = True,
                 use_xyz: bool = True,
                 sample_uniformly: bool = False):
        super().__init__()

        assert len(radii) == len(nsamples) == len(mlps)

        self.npoint = npoint
        self.groupers = nn.ModuleList()
        self.mlps = nn.ModuleList()
        for i in range(len(radii)):
            radius = radii[i]
            nsample = nsamples[i]
            self.groupers.append(
                pointnet2_utils.QueryAndGroup(radius,
                                              nsample,
                                              use_xyz=use_xyz,
                                              sample_uniformly=sample_uniformly
                                              )
                if npoint is not None else pointnet2_utils.GroupAll(use_xyz))
            mlp_spec = mlps[i]
            if use_xyz:
                mlp_spec[0] += 3

            self.mlps.append(pt_utils.SharedMLP(mlp_spec, bn=bn))
Esempio n. 6
0
 def __init__(self, mlp, pool='max', bn=True):
     super().__init__()
     self.mlp = pt_utils.SharedMLP(mlp,
                                   bn=bn,
                                   activation=nn.LeakyReLU(
                                       negative_slope=relu_alpha,
                                       inplace=True))
Esempio n. 7
0
    def __init__(self,
                 num_class,
                 num_heading_bin,
                 num_size_cluster,
                 mean_size_arr,
                 num_proposal,
                 sampling,
                 seed_feat_dim=256,
                 query_feats='seed',
                 iou_class_depend=True):
        super().__init__()

        self.num_class = num_class
        self.num_heading_bin = num_heading_bin
        self.num_size_cluster = num_size_cluster
        self.mean_size_arr = mean_size_arr
        self.num_proposal = num_proposal
        self.sampling = sampling
        self.seed_feat_dim = seed_feat_dim
        self.query_feats = query_feats
        self.iou_class_depend = iou_class_depend

        # class dependent IoU
        self.iou_size = num_class if self.iou_class_depend else 1

        self.mlp_before_iou = pt_utils.SharedMLP(
            [self.seed_feat_dim + 3, 128, 128, 128], bn=True)

        self.conv1_iou = torch.nn.Conv1d(128, 128, 1)
        self.conv2_iou = torch.nn.Conv1d(128, 128, 1)
        self.conv3_iou = torch.nn.Conv1d(
            128,
            3 + num_heading_bin * 2 + num_size_cluster * 3 + self.iou_size, 1)
        self.bn1_iou = torch.nn.BatchNorm1d(128)
        self.bn2_iou = torch.nn.BatchNorm1d(128)
    def __init__(
            self,
            *,
            mlp: List[int],
            npoint: int = None,
            radius: float = None,
            nsample: int = None,
            bn: bool = True,
            use_xyz: bool = True,
            pooling: str = 'max',
            sigma: float = None,  # for RBF pooling
            normalize_xyz: bool = False,  # noramlize local XYZ with radius
            sample_uniformly: bool = False,
            ret_unique_cnt: bool = False):
        super().__init__()

        self.npoint = npoint
        self.radius = radius
        self.nsample = nsample
        self.pooling = pooling
        self.mlp_module = None
        self.use_xyz = use_xyz
        self.sigma = sigma
        if self.sigma is None:
            self.sigma = self.radius / 2
        self.normalize_xyz = normalize_xyz
        self.ret_unique_cnt = ret_unique_cnt

        if npoint is not None:
            self.grouper = pointnet2_utils.QueryAndGroup(
                radius,
                nsample,
                use_xyz=use_xyz,
                ret_grouped_xyz=True,
                normalize_xyz=normalize_xyz,
                sample_uniformly=sample_uniformly,
                ret_unique_cnt=ret_unique_cnt)
        else:
            self.grouper = pointnet2_utils.GroupAll(use_xyz,
                                                    ret_grouped_xyz=True)

        mlp_spec = mlp
        if use_xyz and len(mlp_spec) > 0:
            mlp_spec[0] += 3
        self.mlp_module = pt_utils.SharedMLP(mlp_spec, bn=bn)
Esempio n. 9
0
    def __init__(self,
                 npoint=1024,
                 up_ratio=2,
                 use_normal=False,
                 use_bn=False,
                 use_res=False):
        super().__init__()

        self.npoint = npoint
        self.use_normal = use_normal
        self.up_ratio = up_ratio

        self.npoints = [npoint // 2, npoint // 4, npoint // 8]

        mlps = [[64, 64, 128], [128, 128, 256], [256, 256, 512]]

        fp_mlps = [[128, 128, 128], [256, 128], [256, 256]]

        radius = [0.1, 0.2, 0.3]

        nsamples = [32, 32, 32, 32]

        in_ch = 0 if not use_normal else 3
        self.conv0 = PointnetSAModule(npoint=self.npoint,
                                      radius=radius[0] / 2,
                                      nsample=nsamples[0],
                                      mlp=[in_ch, 32, 32, 64],
                                      use_xyz=True,
                                      use_res=use_res,
                                      bn=use_bn)

        ## for 4 downsample layers
        in_ch = 64
        skip_ch_list = [in_ch]
        self.SA_modules = nn.ModuleList()
        for k in range(len(self.npoints)):
            sa_mlpk = [in_ch] + mlps[k]
            print(' -- sa_mlpk {}, radius {}, nsample {}, npoint {}.'.format(
                sa_mlpk, radius[k], nsamples[k], self.npoints[k]))
            self.SA_modules.append(
                PointnetSAModule(npoint=self.npoints[k],
                                 radius=radius[k],
                                 nsample=nsamples[k],
                                 mlp=sa_mlpk,
                                 use_xyz=True,
                                 use_res=use_res,
                                 bn=use_bn))
            in_ch = mlps[k][-1]
            skip_ch_list.append(in_ch)

        ## upsamples for layer 2 ~ 4
        self.FP_Modules = nn.ModuleList()
        for k in range(len(self.npoints)):
            pre_ch = fp_mlps[
                k + 1][-1] if k < len(self.npoints) - 1 else skip_ch_list[-1]
            fp_mlpk = [pre_ch + skip_ch_list[k]] + fp_mlps[k]
            print(' -- fp_mlpk:', fp_mlpk)
            self.FP_Modules.append(PointnetFPModule(mlp=fp_mlpk, bn=use_bn))

        ## feature Expansion
        in_ch = fp_mlps[0][-1] + 3  # fp output + input xyz
        self.FC_Modules = nn.ModuleList()
        for k in range(up_ratio):
            self.FC_Modules.append(
                pt_utils.SharedMLP([in_ch, 256, 128], bn=use_bn))

        ## coordinate reconstruction
        in_ch = 128
        self.pcd_layer = nn.Sequential(
            pt_utils.SharedMLP([in_ch, 64], bn=use_bn),
            pt_utils.SharedMLP([64, 3], activation=None, bn=False))
 def __init__(self, *, mlp: List[int], bn: bool = True):
     super().__init__()
     self.mlp = pt_utils.SharedMLP(mlp, bn=bn)