项目文件夹

文件
Tong He 558673e139 [Model] PointNet and PointNet++ for point cloud (#1510)
* commit patch

* commit patch

* pointnet basic

* fix data

* reorg

* reorg

* temp status

* remove validate set

* add partseg data and model

* partseg miou

* clean up

* fix loss

* network definition match paper

* fix

* fix miou

* update data format

* fix

* fix

* working pointnet ssg cls

* avoid some pytorch bug

* fix script

* update hyperparams

* add msg module

* try different dataset

* update new dataset info

* quick fix to subgraph

* fix speed

* update training

* update

* fix bs

* update docstring

* update

* update

* remove parallel reduction in fps

* switch to kernel fps, training is 30% faster

Co-authored-by: Ubuntu <ubuntu@ip-172-31-20-181.us-west-2.compute.internal>
2020-06-22 19:50:40 +08:00

47 行
1.5 KiB
Python

"""Farthest Point Sampler for pytorch Geometry package"""
#pylint: disable=no-member, invalid-name
import torch as th
from torch import nn
from ..capi import farthest_point_sampler
class FarthestPointSampler(nn.Module):
"""Farthest Point Sampler without the need to compute all pairs of distance.
In each batch, the algorithm starts with the sample index specified by ``start_idx``.
Then for each point, we maintain the minimum to-sample distance.
Finally, we pick the point with the maximum such distance.
This process will be repeated for ``sample_points`` - 1 times.
Parameters
----------
npoints : int
The number of points to sample in each batch.
"""
def __init__(self, npoints):
super(FarthestPointSampler, self).__init__()
self.npoints = npoints
def forward(self, pos):
r"""Memory allocation and sampling
Parameters
----------
pos : tensor
The positional tensor of shape (B, N, C)
Returns
-------
tensor of shape (B, self.npoints)
The sampled indices in each batch.
"""
device = pos.device
B, N, C = pos.shape
pos = pos.reshape(-1, C)
dist = th.zeros((B * N), dtype=pos.dtype, device=device)
start_idx = th.randint(0, N - 1, (B, ), dtype=th.long, device=device)
result = th.zeros((self.npoints * B), dtype=th.long, device=device)
farthest_point_sampler(pos, B, self.npoints, dist, start_idx, result)
return result.reshape(B, self.npoints)