def __init__(self, num_classes): super(PointNet, self).__init__() nn = Seq(Lin(3, 64), ReLU(), Lin(64, 64)) self.conv1 = PointConv(local_nn=nn) nn = Seq(Lin(67, 128), ReLU(), Lin(128, 128)) self.conv2 = PointConv(local_nn=nn) nn = Seq(Lin(131, 256), ReLU(), Lin(256, 256)) self.conv3 = PointConv(local_nn=nn) self.lin1 = Lin(256, 256) self.lin2 = Lin(256, 256) self.lin3 = Lin(256, num_classes)
def __init__(self): super(PointNet, self).__init__() self.local_sa1 = PointConv( Seq(Lin(3, 64), ReLU(), Lin(64, 64), ReLU(), Lin(64, 128))) self.local_sa2 = PointConv( Seq(Lin(131, 128), ReLU(), Lin(128, 128), ReLU(), Lin(128, 256))) self.global_sa = Seq(Lin(259, 256), ReLU(), Lin(256, 512), ReLU(), Lin(512, 1024)) self.lin1 = Lin(1024, 512) self.lin2 = Lin(512, 256) self.lin3 = Lin(256, 10)
def __init__(self, in_channels, int_channels, out_channels, ratio=0.5, r=0.2): """ PointNet++ building block, input args: in_channels shape: [-1, in_channels + num_dimensions] out_channels shape: [-1, out_channels] """ super().__init__() self.in_channels = in_channels self.out_channels = out_channels self.ratio = ratio self.r = r self.conv = PointConv( nn.Sequential( nn.Sequential(nn.Linear(in_channels, int_channels), nn.BatchNorm1d(int_channels), nn.ReLU(inplace=True)), nn.Sequential(nn.Linear(int_channels, int_channels), nn.BatchNorm1d(int_channels), nn.ReLU(inplace=True)), nn.Sequential(nn.Linear(int_channels, out_channels), nn.BatchNorm1d(out_channels), nn.ReLU(inplace=True))))
def test_point_conv(): in_channels, out_channels = (16, 32) edge_index = torch.tensor([[0, 0, 0, 1, 2, 3], [1, 2, 3, 0, 0, 0]]) num_nodes = edge_index.max().item() + 1 x = torch.randn((num_nodes, in_channels)) pos = torch.rand((num_nodes, 3)) local_nn = Seq(Lin(in_channels + 3, 32), ReLU(), Lin(32, out_channels)) global_nn = Seq(Lin(out_channels, out_channels)) conv = PointConv(local_nn, global_nn) assert conv.__repr__() == ( 'PointConv(local_nn=Sequential(\n' ' (0): Linear(in_features=19, out_features=32, bias=True)\n' ' (1): ReLU()\n' ' (2): Linear(in_features=32, out_features=32, bias=True)\n' '), global_nn=Sequential(\n' ' (0): Linear(in_features=32, out_features=32, bias=True)\n' '))') assert conv(x, pos, edge_index).size() == (num_nodes, out_channels)
def __init__(self, num_classes): super(GCNPool, self).__init__() self.conv1 = GCNConv(6, 64, cached=False, normalize=not True) self.conv2 = GCNConv(64 + 6, 128, cached=False, normalize=not True) self.conv3 = GCNConv(128 + 9, 256, cached=False, normalize=not True) # CAREFUL: If modifying here, check line 202 in experiments.py for pretrained model self.lin1 = torch.nn.Linear(256, num_classes) self.con_int = PointConv()
def __init__(self, num_classes): super(Defense_PointNet, self).__init__() features = [] nn = Seq(Lin(3, 64), ReLU(), Lin(64, 64)) features.append(PointConv(local_nn=nn)) nn = Seq(Lin(67, 128), ReLU(), Lin(128, 128)) features.append(PointConv(local_nn=nn)) nn = Seq(Lin(131, 256), ReLU(), Lin(256, 256)) features.append(PointConv(local_nn=nn)) self.features = torch.nn.ModuleList(features) layers = [] layers.append(Lin(256, 256)) layers.append(Lin(256, 256)) layers.append(Lin(256, num_classes)) self.classifier = torch.nn.ModuleList(layers) layers = [] layers.append(Lin(256, 256)) layers.append(Lin(256, 2)) self.discriminator = torch.nn.ModuleList(layers)
def __init__(self, r, ratio_train, ratio_test, nn): """ Set abstraction module, which is proposed by Pointnet++. r: ball query radius ratio_train: sampling ratio in further points sampling (FPS) during training. ratio_test: sampling ratio in FPS during test. nn: mlp. """ super(SAModule, self).__init__() self.r = r self.ratio_train = ratio_train self.ratio_test = ratio_test self.conv = PointConv(nn)
def __init__(self, sample_points, r_list, group_sample_size_list, nn_list): super(SAModuleMSG, self).__init__() assert (len(nn_list) == len(group_sample_size_list) and len(r_list) == len(nn_list) ) #all have to have the same size self.sample_points = sample_points self.r_list = r_list self.group_sample_size = group_sample_size_list self.conv_list = torch.nn.ModuleList() for i in range(len(nn_list)): #create a pointConv for each radius self.conv_list.append(PointConv(nn_list[i]))
def test_point_conv(): x1 = torch.randn(4, 16) pos1 = torch.randn(4, 3) pos2 = torch.randn(2, 3) edge_index = torch.tensor([[0, 1, 2, 3], [0, 0, 1, 1]]) row, col = edge_index adj = SparseTensor(row=row, col=col, sparse_sizes=(4, 4)) local_nn = Seq(Lin(16 + 3, 32), ReLU(), Lin(32, 32)) global_nn = Seq(Lin(32, 32)) conv = PointConv(local_nn, global_nn) assert conv.__repr__() == ( 'PointConv(local_nn=Sequential(\n' ' (0): Linear(in_features=19, out_features=32, bias=True)\n' ' (1): ReLU()\n' ' (2): Linear(in_features=32, out_features=32, bias=True)\n' '), global_nn=Sequential(\n' ' (0): Linear(in_features=32, out_features=32, bias=True)\n' '))') out = conv(x1, pos1, edge_index) assert out.size() == (4, 32) assert torch.allclose(conv(x1, pos1, adj.t()), out, atol=1e-6) t = '(OptTensor, Tensor, Tensor) -> Tensor' jit = torch.jit.script(conv.jittable(t)) assert jit(x1, pos1, edge_index).tolist() == out.tolist() t = '(OptTensor, Tensor, SparseTensor) -> Tensor' jit = torch.jit.script(conv.jittable(t)) assert torch.allclose(jit(x1, pos1, adj.t()), out, atol=1e-6) adj = adj.sparse_resize((4, 2)) out = conv(x1, (pos1, pos2), edge_index) assert out.size() == (2, 32) assert conv((x1, None), (pos1, pos2), edge_index).tolist() == out.tolist() assert torch.allclose(conv(x1, (pos1, pos2), adj.t()), out, atol=1e-6) assert torch.allclose(conv((x1, None), (pos1, pos2), adj.t()), out, atol=1e-6) t = '(PairOptTensor, PairTensor, Tensor) -> Tensor' jit = torch.jit.script(conv.jittable(t)) assert jit((x1, None), (pos1, pos2), edge_index).tolist() == out.tolist() t = '(PairOptTensor, PairTensor, SparseTensor) -> Tensor' jit = torch.jit.script(conv.jittable(t)) assert torch.allclose(jit((x1, None), (pos1, pos2), adj.t()), out, atol=1e-6)
def __init__(self, nIn, nOut, conv_args, ratio, radius, max_neighbors=64): super(SAModule, self).__init__() """This module acts as a pooling/conv layer. Taken from pytorch-geometric examples.""" self.ratio = ratio self.r = radius self.K = max_neighbors # set up convolution self.conv_name = conv_args['name'] if conv_args['name'] == 'PointConv': nn = MLP([nIn + 3, int((nIn + 3 + nOut) / 2), nOut]) self.conv = PointConv(nn) elif conv_args['name'] == 'GraphConv': self.conv = GraphConv(nIn, nOut, aggr=conv_args['aggr']) elif conv_args['name'] == 'PPFConv': nn = MLP([nIn + 4, int((nIn + 4 + nOut) / 2), nOut]) self.conv = PPFConv(nn) self.conv.aggr = conv_args['aggr']
def __init__(self, ratio=None, radius=None, radius_num_point=None, down_conv_nn=None, *args, **kwargs): super(SAModule, self).__init__( FPSSampler(ratio=ratio), MultiscaleRadiusNeighbourFinder( radius, max_num_neighbors=radius_num_point), *args, **kwargs) local_nn = MLP(down_conv_nn) if down_conv_nn is not None else None self._conv = PointConv(local_nn=local_nn, global_nn=None) self._radius = radius self._ratio = ratio self._num_points = radius_num_point
def __init__(self, ratio, r, nn): super(SAModule, self).__init__() self.ratio = ratio self.r = r self.conv = PointConv(nn)
def __init__(self, sample_points, r, sample_size, nn): super(SAModule, self).__init__() self.sample_points = sample_points self.r = r self.sample_size = sample_size self.conv = PointConv(nn)
def __init__(self, r, sample_size, nn): super(SAModuleFullPoint, self).__init__() self.r = r self.sample_size = sample_size self.conv = PointConv(nn)
def __init__(self, ratio, r, nn, max_num_neighbors=64): super(SAModule, self).__init__() self.ratio = ratio self.r = r self.conv = PointConv(nn) self.max_num_neighbors = max_num_neighbors
def __init__(self, ratio, r, nn): super(SAModule, self).__init__() self.ratio = torch.tensor(ratio).float() self.r = r self.conv = PointConv(nn)
def __init__(self, sample_radio, radius, max_num_neighbors, mlp): super(PointNet2SAModule, self).__init__() self.sample_ratio = sample_radio self.radius = radius self.max_num_neighbors = max_num_neighbors self.point_conv = PointConv(mlp)
def __init__(self, ratio, r, channels): super(SAModule, self).__init__() self.ratio = ratio self.r = r self.conv = PointConv() self.mlp = MLPModule(channels)
def __init__(self, ratio, r, nn): super(SAModule, self).__init__() self.ratio = ratio self.r = r self.conv = PointConv(nn, add_self_loops=False)