Package: difw
Finite-dimensional spaces of simple, fast, and highly-expressive diffeomorphisms derived from parametric, continuously-defined, velocity fields in Numpy and Pytorch. DIFW supports one-dimensional diffeomorphic transformations.This repo is based on thelibcpablibrary that supports diffeomorphic transformations in 1D (time series), 2D (images) and 3D (volumetric images).
Thanks to Nicki Skafte Detlefsen, Oren Freifeld and Ron Shapira Weber for their help and guidance.Getting StartedThe following code transforms a regular grid using a diffeomorphic curve parametrizedtheta:# Import difw libraryimportdifw# Transformation instanceT=difw.Cpab(tess_size=5,backend="numpy",device="cpu",zero_boundary=True,basis="qr")# Generate gridgrid=T.uniform_meshgrid(100)# Transformation parameterstheta=T.identity(epsilon=1)# Transform gridgrid_t=T.transform_grid(grid,theta)In this example, the tesselation is composed of 5 intervals, and thezero_boundarycondition set toTrueconstraints the velocity at the tesselation boundary (in this case, atx=0andx=1). The regular grid has 100 equally spaced points.T.visualize_tesselation()The velocity field is formed by a continuous piecewise affine function defined over 5 intervals. The parametersthetarepresent a basis of the null space for all continuous piecewise affine functions composed of 5 intervals. In this case, we have used the QR decomposition to build the basis. See the API documentation for more details about the transformation options.Taking into account the zero velocity constraints at the boundary, only 4 dimensions or degree of freedom are left to play with, and that indeed is the dimensionality oftheta, a vector of 4 values.T.visualize_velocity(theta)We can visualize the generated transformation based on the parameterstheta:T.visualize_deformgrid(theta)In addition, for optimization tasks, it is useful to obtain the gradient of the transformation with respect to parameterstheta. The gradient function can be obtained in closed-form solution. There are 4 different functions, one per dimension intheta:T.visualize_gradient(theta)CitationsThis repository was presented at the International Conference of Machine Learning (ICML 2022).@inproceedings{martinez2022closed,title={Closed-Form Diffeomorphic Transformations for Time Series Alignment},author={Martinez, I{\~n}igo and Viles, Elisabeth and Olaizola, Igor G},booktitle={International Conference on Machine Learning},pages={15122--15158},year={2022},organization={PMLR}}Furthermore, please cite previous articles by Freifeld et al. and Shapira Weber et al. that are essential to this work.@article{freifeld2017transformations,title={Transformations based on continuous piecewise-affine velocity fields},author={Freifeld, Oren and Hauberg, S{\o}ren and Batmanghelich, Kayhan and Fisher, Jonn W},journal={IEEE transactions on pattern analysis and machine intelligence},volume={39},number={12},pages={2496--2509},year={2017},publisher={IEEE}}@inproceedings{freifeld2015highly,title={Highly-expressive spaces of well-behaved transformations: Keeping it simple},author={Freifeld, Oren and Hauberg, Soren and Batmanghelich, Kayhan and Fisher, John W},booktitle={Proceedings of the IEEE International Conference on Computer Vision},pages={2911--2919},year={2015}}@article{shapira2019diffeomorphic,title={Diffeomorphic temporal alignment nets},author={Shapira Weber, Ron A and Eyal, Matan and Skafte, Nicki and Shriki, Oren and Freifeld, Oren},journal={Advances in Neural Information Processing Systems},volume={32},year={2019}}InstallationAs the compileddifwpackage is hosted on the Python Package Index (PyPI) you can easily install it withpip.
To installdifw, run this command in your terminal of choice:$pipinstalldifwor, alternatively:$python-mpipinstalldifwIf you want to getdifw’s latest version, you can refer to the
repository hosted at github:python -m pip install https://github.com/imartinezl/difw/archive/master.zipEnvironment SetupRequirementsdifwbuilds onnumpy,torch,scipy,ninja,  andmatplotliblibraries.Python 3To find out which version ofpythonyou have, open a terminal window and try the following command:$python3--versionPython 3.6.9If you havepython3on your machine, then this command should respond with a version number. If you do not havepython3installed, follow theseinstructions.Pippipis the reference Python package manager. It’s used to install and update packages. In casepipis not installed in your OS, follow theseprocedure.Virtual Environmentvenvcreates a “virtual” isolated Python installation and installs packages into that virtual installation. It is always recommended to use a virtual environment while developing Python applications. To create a virtual environment, go to your project’s directory and run venv.$python3-mvenvenvBefore you can start installing or using packages in your virtual environment you’ll need to activate it.$sourceenv/bin/activateSource Codedifw is developed on GitHub, where the code isalways available.You can either clone the public repository:$gitclonegit://github.com/imartinezl/difw.gitOr, download thetarball:$curl-OLhttps://github.com/imartinezl/difw/tarball/main#optionally,zipballisalsoavailable(forWindowsusers).Once you have a copy of the source, you can embed it in your own Python
package, or install it into your site-packages easily:$cddifw$python-mpipinstall.MIT LicenseCopyright (c) 2021 Iñigo MartínezPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.