Git Product home page Git Product logo

simple-invertible-fft-convolutions's Introduction

Simple invertible FFT convolutions

Convolution operations are equivalent to multiplication by Toeplitz matrices, and as a result they can often be invertible operations. A circular convolution is especially easy to invert because its corresponding matrix is a circulant matrix, which is diagonal in the Fourier basis; this is the Convolution Theorem. Thus it is (theoretically) easy and efficient to invert circular convolutions by changing the basis of the convolution operation to the Fourier basis using FFT and then inverting each of the diagonal elements of the (now diagonal) convolution matrix.

Using this strategy to invert the native PyTorch convolution implementations is a bit tricky, though, because the PyTorch definition of a convolution is different from the definition of a convolution in the Convolution Theorem. Specifically, the Convolution Theorem version is shifted and inverted (in all dimensions):

This repo provides minimalist implementations of 1D and 2D invertible FFT convolutions that are compatible with torch.nn.Conv1D and torch.nn.Conv2D. The goal here is simplicity, so no attempt is made to replicate strides and the number of channels is fixed at 1.

Implementations:

  • 1D convolutions and inverses: fft_conv1d.py
  • 2D convolutions and inverses: fft_conv2d.py

Example usage:

  • 1D convolutions and inverses: test_fft_conv1d.py
  • 2D convolutions and inverses: test_fft_conv2d.py

Other resources

I recommend the paper Orthogonalizing Convolutional Layers with the Cayley Transform, which discusses invertible convolutions and other, more advanced uses of FFT convolutions. Their github repo provides two especially useful files:

  • FFT convolutions.ipynb: pedagogical walkthrough notebook for building FFT convolutions
  • fftconv.py: implementation of FFT convolution that is fully compatible with (and, indeed, subclassed from) torch.nn.Convd2d, including functionality for channels and strides. I actually can't get this to work with the tests in this repo, so I might misunderstand it, or there might be a bug in it, or maybe something has changed in Torch since fftconv.py was written, but it might serve as a useful example for someone who wants to implement channels for FFT convolutions.

simple-invertible-fft-convolutions's People

Contributors

brendanedwardgavin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.