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, *, 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] """# my code: self.C_in_att = mlps[0][0]+3 self.C_out_att = self.C_in_att if first_layer else math.floor(self.C_in_att/4) self.mlp_for_att1 = nn.Conv1d(in_channels = self.C_in_att, out_channels = self.C_out_att, kernel_size = 1, stride = 1, bias = False) self.mlp_for_att2 = nn.Conv1d(in_channels = self.C_out_att, out_channels = 1, kernel_size = 1, stride = 1, bias = False) nn.init.kaiming_normal_(self.mlp_for_att1.weight) nn.init.kaiming_normal_(self.mlp_for_att2.weight) self.first_layer = first_layer """ 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))