Skip to content

Commit

Permalink
performance up cpd
Browse files Browse the repository at this point in the history
  • Loading branch information
neka-nat committed Feb 23, 2024
1 parent 9c1c9a4 commit 64ba477
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-20.04, windows-2022]
openmp-on: [true, false]
exclude:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ Execute an example script for measuring time.
OMP_NUM_THREADS=1 python time_measurement.py
# Results [s]
# ICP(Open3D): 0.02030642901081592
# CPD: 3.6435861150093842
# SVR: 0.5795929960149806
# GMMTree: 0.34479290700983256
# FilterReg: 0.039795294986106455
# ICP(Open3D): 0.02212289097951725
# CPD: 0.1632105699973181
# SVR: 0.1983455469890032
# GMMTree: 0.27672973900916986
# FilterReg: 0.015339541976572946
```

## Citing
Expand Down
7 changes: 6 additions & 1 deletion probreg/cpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np
import open3d as o3
import six
from scipy.spatial import distance as scipy_distance

from . import math_utils as mu
from . import transformation as tf
Expand Down Expand Up @@ -44,14 +45,17 @@ def __init__(self, source: Optional[np.ndarray] = None, use_cuda: bool = False)
self._callbacks = []
if use_cuda:
import cupy as cp
from cupyx.scipy.spatial import distance as cupy_distance

from . import cupy_utils

self.xp = cp
self.distance_module = cupy_distance
self.cupy_utils = cupy_utils
self._squared_kernel_sum = cupy_utils.squared_kernel_sum
else:
self.xp = np
self.distance_module = scipy_distance
self._squared_kernel_sum = mu.squared_kernel_sum

def set_source(self, source: np.ndarray) -> None:
Expand All @@ -67,7 +71,8 @@ def _initialize(self, target: np.ndarray) -> MstepResult:
def expectation_step(self, t_source: np.ndarray, target: np.ndarray, sigma2: float, w: float = 0.0) -> EstepResult:
"""Expectation step for CPD"""
assert t_source.ndim == 2 and target.ndim == 2, "source and target must have 2 dimensions."
pmat = self.xp.stack([self.xp.sum(self.xp.square(target - ts), axis=1) for ts in t_source])
pmat = self.distance_module.cdist(t_source, target, "sqeuclidean")
# pmat = self.xp.stack([self.xp.sum(self.xp.square(target - ts), axis=1) for ts in t_source])
pmat = self.xp.exp(-pmat / (2.0 * sigma2))

c = (2.0 * np.pi * sigma2) ** (t_source.shape[1] * 0.5)
Expand Down
2 changes: 1 addition & 1 deletion probreg/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.6"
__version__ = "0.3.7"
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "probreg"
version = "0.3.6"
description = ""
version = "0.3.7"
description = "Probablistic point cloud resitration algorithms"
authors = ["nekanat <[email protected]>"]
license = "MIT"

Expand Down

0 comments on commit 64ba477

Please sign in to comment.