This restortion contains example code for sliced optimal partial transport introduced in Sliced optimal partial transport. All code is written in Python / numpy / scipy /torch without any additional exotic dependencies. The code reproduces all the numerical examples in the paper.
To run the code, you must first install Pytorch, numba
conda install numba
and PythonOT
pip install pot
We also provide the C++ implementation of our 1D OPT solver. To use the C++ solver, you must first compile the 1D Partial Optimal Transport with pybind11.
Start by cloning the pybind11 repo:
conda install -c conda-forge pybind11
Ensure cmake, cython, and pytest are installed:
conda install cmake
conda install pip
pip install cython pytest
Then use:
cd pybin11
mkdir build
cd build
cmake -DDOWNLOAD_CATCH=ON ..
cmake --build . --config Release --target check
You can use the following to compile the opt1d.cpp:
c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) opt1d.cpp -o opt1d$(python3-config --extension-suffix)
or (if the first one does not work.)
c++ -O3 -Wall -shared -std=c++11 -fPIC $(python3 -m pybind11 --includes) opt1d.cpp -o opt1d.so
You will get a compiled c++ file. In my computer, it is
opt1d.cpython-310-x86_64-linux-gnu.so
or
opt1d.so
Please ensure to replace the paths with your relevant paths.
If all has gone well, then we can test the code in Python:
python3 test_opt1d.py
this should results in saved plot as follows.
First please ensure to replace the paths with your relevant paths.
The file code/sopt/lib_ot.py contains our 1-D optimal partial transport (OPT problem) solver. In particular, it contains the following functions, most of which are accelarated by numba:
The file code/sopt/lib_shape.py contains our method for shape registration experiment based on our OPT solver. In particular it contains the following functions:
The file code/sopt/lib_color.py contains our color adaptation method based on our 1-D OPT solver. In particular, it contains the following functions:
[1] Marco Cuturi. Sinkhorn distances: Lightspeed computation of optimal transport. Advances in neural information processing systems, 26, 2013
[2] Nicolas Bonneel and David Coeurjolly. SPOT: sliced partial optimal transport. ACM Transactions on Graphics, 38(4):1–13, 2019
[3] haoyi Du, Nanning Zheng, Shihui Ying, Qubo You, and Yang Wu. An extension of the icp algorithm considering scale factor. In 2007 IEEE International Conference on Image Processing, volume 5, pages V–193. IEEE, 2007
[4] Shinji Umeyama. Least-squares estimation of transformation parameters between two point patterns. IEEE Transactions on Pattern Analysis & Machine Intelligence, 13(04):376–380, 1991.
[5] Ferradans, S., Papadakis, N., Peyre, G., & Aujol, J. F. (2014). Regularized discrete optimal transport. SIAM Journal on Imaging Sciences, 7(3), 1853-1882.