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))
def __init__(self, *, mlp: List[int], npoint: int = None, radius: float = None, nsample: int = None, bn: bool = True, use_xyz: bool = True): super().__init__() self.npoint = npoint self.groupers = nn.ModuleList() self.mlps = nn.ModuleList() if self.npoint is not None: assert radius is not None assert nsample is not None self.groupers.append( pointnet2_utils.QueryAndGroup(radius, nsample, use_xyz=use_xyz)) else: self.groupers.append(pointnet2_utils.GroupAll(use_xyz=use_xyz)) if use_xyz: mlp[0] += 3 self.mlps.append(pt_utils.SharedMLP(mlp, bn=bn))
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))
def __init__( self, *, mlp: List[int], 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.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 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) 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)
def __init__(self, npoint, radii, nsamples, mlps, bn=True, use_xyz=True): # type: (PointnetSAModuleMSGPN2, int, List[float], List[int], List[List[int]], bool, bool) -> None super(PointnetSAModuleMSGPN2, self).__init__() assert len(radii) == len(nsamples) == len(mlps) self.npoint = npoint self.groupers = nn.ModuleList() self.mlps = nn.ModuleList() self.out_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) if npoint is not None else pointnet2_utils.GroupAll(use_xyz)) mlp_spec = mlps[i] self.out_mlps.append( nn.Sequential(nn.Conv1d(mlp_spec[1], mlp_spec[-1], 1), nn.BatchNorm1d(mlp_spec[-1]), nn.ReLU(inplace=True))) mlp_spec = mlp_spec[0:2] if use_xyz: mlp_spec[0] += 3 self.mlps.append(pt_utils.SharedMLP(mlp_spec, bn=bn))
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( pointnet2_utils.QueryAndGroup(radius, nsample, use_xyz=use_xyz) 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, instance_norm=instance_norm)) self.pool_method = pool_method
def __init__(self, *, npoint: int, radii: List[float], nsamples: List[int], mlps: List[List[int]], group_number=1, use_xyz: bool = True, pool: bool = False, before_pool: bool = False, after_pool: bool = False, bias=True, init=nn.init.kaiming_normal): super().__init__() assert len(radii) == len(nsamples) == len(mlps) self.pool = pool self.npoint = npoint self.groupers = nn.ModuleList() self.mlps = nn.ModuleList() if pool: C_in = (mlps[0][0] + 3) if use_xyz else mlps[0][0] C_out = mlps[0][1] pconv = nn.Conv2d(in_channels=C_in, out_channels=C_out, kernel_size=(1, 1), stride=(1, 1), bias=bias) init(pconv.weight) if bias: nn.init.constant(pconv.bias, 0) convs = [pconv] for i in range(len(radii)): radius = radii[i] nsample = nsamples[i] self.groupers.append( pointnet2_utils.QueryAndGroup(radius, nsample, use_xyz=use_xyz) if npoint is not None else pointnet2_utils.GroupAll(use_xyz)) mlp_spec = mlps[i] if use_xyz: mlp_spec[0] += 3 if npoint is None: self.mlps.append( pt_utils.GloAvgConv(C_in=mlp_spec[0], C_out=mlp_spec[1])) elif pool: self.mlps.append( pt_utils.PointConv(C_in=mlp_spec[0], C_out=mlp_spec[1], convs=convs)) else: self.mlps.append( pt_utils.EnhancedPointConv(C_in=mlp_spec[0], C_out=mlp_spec[1], group_number=group_number, before_pool=before_pool, after_pool=after_pool))
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, binary='None'): 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 if binary == 'None': self.mlp_module = pt_utils.SharedMLP(mlp_spec, bn=bn) elif binary == 'BiMLP': self.mlp_module = BiMLP(mlp_spec, BiLinear=BiLinearLSR) elif binary == 'BiSharedMLP': self.mlp_module = pt_utils.BiSharedMLP(mlp_spec, bn=bn, lsr=False) elif binary == 'BiLSRSharedMLP': self.mlp_module = pt_utils.BiSharedMLP(mlp_spec, bn=bn, lsr=True) else: raise NotImplementedError
def __init__( self, *, mlp: List[int], npoint: int = None, split: int = 18, 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, same_idx: bool = False, use_feature: bool = True ): super().__init__() self.npoint = npoint self.radius = radius self.split = split 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 self.same_idx = same_idx if npoint is not None: ''' self.grouper = pointnet2_utils.PairwiseGroup(radius, nsample, use_xyz=use_xyz, ret_grouped_xyz=True, normalize_xyz=normalize_xyz, sample_uniformly=sample_uniformly, ret_unique_cnt=ret_unique_cnt, use_feature=use_feature) ''' 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, use_feature=use_feature, ret_idx=True) else: self.grouper = pointnet2_utils.GroupAll(use_xyz, ret_grouped_xyz=True) mlp_spec = mlp if use_feature and len(mlp_spec)>0: mlp_spec[0] += mlp_spec[0] if use_xyz and len(mlp_spec)>0: mlp_spec[0] += 3 self.mlp_module = nn.ModuleList() for i in range(split): self.mlp_module.append(pt_utils.SharedMLP(mlp_spec, bn=bn))
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', normalize_xyz: bool = False, # noramlize local XYZ with radius sample_uniformly: bool = False, ret_unique_cnt: bool = False): super().__init__() self.npoint = npoint self.nsample = nsample self.pooling = pooling self.mlp_module = None self.use_xyz = use_xyz self.normalize_xyz = normalize_xyz self.ret_unique_cnt = ret_unique_cnt ''' if npoint is not None: print ("not used for plane") else: ''' self.grouper1 = 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) self.grouper2 = 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_module1 = pt_utils.SharedMLP(mlp_spec, bn=bn) self.mlp_module2 = pt_utils.SharedMLP(mlp_spec, bn=bn)
def __init__( self, *, npoint: int, radii: List[float], nsamples: List[int], mlps: List[List[int]], use_xyz: bool = True, bias=True, init=nn.init.kaiming_normal, first_layer=False, last_layer=False, ): super().__init__() assert len(radii) == len(nsamples) == len(mlps) self.npoint = npoint self.groupers = nn.ModuleList() self.mlps = nn.ModuleList() mlp = MLP(mlps[0]) for i in range(len(radii)): radius = radii[i] nsample = nsamples[i] if npoint is not None: self.groupers.append( pointnet2_utils.QueryAndGroup(radius, nsample, use_xyz=use_xyz)) self.mlps.append( pt_utils.PointNetConv(mlp=mlp, first_layer=first_layer, last_layer=last_layer)) else: # global pooling self.groupers.append(pointnet2_utils.GroupAll(False)) self.mlps.append(pt_utils.GloAvgConv(mlp=MLP(mlps[i])))
def __init__( self, *, npoint: int, radii: List[float], nsamples: List[int], mlps: List[List[int]], use_xyz: bool = True, bias = True, init = nn.init.kaiming_normal, first_layer = False, relation_prior = 1 ): super().__init__() assert len(radii) == len(nsamples) == len(mlps) self.npoint = npoint self.groupers = nn.ModuleList() self.mlps = nn.ModuleList() # initialize shared mapping functions C_in = (mlps[0][0] + 3) if use_xyz else mlps[0][0] C_out = mlps[0][1] if relation_prior == 0: in_channels = 1 elif relation_prior == 1 or relation_prior == 2: in_channels = 10 else: assert False, "relation_prior can only be 0, 1, 2." if first_layer: mapping_func1 = nn.Conv2d(in_channels = in_channels, out_channels = math.floor(C_out / 2), kernel_size = (1, 1), stride = (1, 1), bias = bias) mapping_func2 = nn.Conv2d(in_channels = math.floor(C_out / 2), out_channels = 16, kernel_size = (1, 1), stride = (1, 1), bias = bias) xyz_raising = nn.Conv2d(in_channels = C_in, out_channels = 16, kernel_size = (1, 1), stride = (1, 1), bias = bias) init(xyz_raising.weight) if bias: nn.init.constant(xyz_raising.bias, 0) elif npoint is not None: mapping_func1 = nn.Conv2d(in_channels = in_channels, out_channels = math.floor(C_out / 4), kernel_size = (1, 1), stride = (1, 1), bias = bias) mapping_func2 = nn.Conv2d(in_channels = math.floor(C_out / 4), out_channels = C_in, kernel_size = (1, 1), stride = (1, 1), bias = bias) if npoint is not None: init(mapping_func1.weight) init(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 = C_in if not first_layer else 16, out_channels = C_out, kernel_size = 1, stride = 1, bias = bias) init(cr_mapping.weight) nn.init.constant(cr_mapping.bias, 0) if first_layer: mapping = [mapping_func1, mapping_func2, cr_mapping, xyz_raising] elif npoint is not None: mapping = [mapping_func1, mapping_func2, cr_mapping] for i in range(len(radii)): radius = radii[i] nsample = nsamples[i] self.groupers.append( pointnet2_utils.QueryAndGroup(radius, nsample, use_xyz=use_xyz) if npoint is not None else pointnet2_utils.GroupAll(use_xyz) ) mlp_spec = mlps[i] if use_xyz: mlp_spec[0] += 3 if npoint is not None: self.mlps.append(pt_utils.SharedRSConv(mlp_spec, mapping = mapping, relation_prior = relation_prior, first_layer = first_layer)) else: # global convolutional pooling self.mlps.append(pt_utils.GloAvgConv(C_in = C_in, C_out = C_out))