From 196b1af7aec80d3f64de0ce060b37deaa9f978b4 Mon Sep 17 00:00:00 2001 From: Si11ium Date: Tue, 19 May 2020 17:15:01 +0200 Subject: [PATCH] Dataset for whole pointclouds with farthest point sampling _incomplete_ --- .../new_project/datasets/template_dataset.py | 8 ++++++- point_toolset/__init__.py | 0 point_toolset/sampling.py | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 point_toolset/__init__.py create mode 100644 point_toolset/sampling.py diff --git a/_templates/new_project/datasets/template_dataset.py b/_templates/new_project/datasets/template_dataset.py index 7f5a373..b391a56 100644 --- a/_templates/new_project/datasets/template_dataset.py +++ b/_templates/new_project/datasets/template_dataset.py @@ -3,4 +3,10 @@ from torch.utils.data import Dataset class TemplateDataset(Dataset): def __init__(self, *args, **kwargs): - super(TemplateDataset, self).__init__() \ No newline at end of file + super(TemplateDataset, self).__init__() + + def __len__(self): + pass + + def __getitem__(self, item): + return item diff --git a/point_toolset/__init__.py b/point_toolset/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/point_toolset/sampling.py b/point_toolset/sampling.py new file mode 100644 index 0000000..37f309c --- /dev/null +++ b/point_toolset/sampling.py @@ -0,0 +1,24 @@ +import numpy as np + + +class FarthestpointSampling(): + + def __init__(self, K): + self.k = K + + def __call__(self, pts, *args, **kwargs): + + if pts.shape[0] < self.k: + return pts + + def calc_distances(p0, points): + return ((p0[:3] - points[:, :3]) ** 2).sum(axis=1) + + farthest_pts = np.zeros((self.k, pts.shape[1])) + farthest_pts[0] = pts[np.random.randint(len(pts))] + distances = calc_distances(farthest_pts[0], pts) + for i in range(1, self.k): + farthest_pts[i] = pts[np.argmax(distances)] + distances = np.minimum(distances, calc_distances(farthest_pts[i], pts)) + + return farthest_pts