PyTorch implementation of the wavelet analysis from Torrence & Compo

Overview

Continuous Wavelet Transforms in PyTorch

This is a PyTorch implementation for the wavelet analysis outlined in Torrence and Compo (BAMS, 1998). The code builds upon the excellent implementation of Aaron O'Leary by adding a PyTorch filter bank wrapper to enable fast convolution on the GPU. Specifically, the code was written to speed-up the CWT computation for a large number of 1D signals and relies on torch.nn.Conv1d for convolution.

PyTorch Wavelets

Citation

If you found this code useful, please cite our paper Repetition Estimation (IJCV, 2019):

@article{runia2019repetition,
  title={Repetition estimation},
  author={Runia, Tom FH and Snoek, Cees GM and Smeulders, Arnold WM},
  journal={International Journal of Computer Vision},
  volume={127},
  number={9},
  pages={1361--1383},
  year={2019},
  publisher={Springer}
}

Usage

In addition to the PyTorch implementation defined in WaveletTransformTorch the original SciPy version is also included in WaveletTransform for completeness. As the GPU implementation highly benefits from parallelization, the cwt and power methods expect signal batches of shape [num_signals,signal_length] instead of individual signals.

import numpy as np
from wavelets_pytorch.transform import WaveletTransform        # SciPy version
from wavelets_pytorch.transform import WaveletTransformTorch   # PyTorch version

dt = 0.1         # sampling frequency
dj = 0.125       # scale distribution parameter
batch_size = 32  # how many signals to process in parallel

# Batch of signals to process
batch = [batch_size x signal_length] 

# Initialize wavelet filter banks (scipy and torch implementation)
wa_scipy = WaveletTransform(dt, dj)
wa_torch = WaveletTransformTorch(dt, dj, cuda=True)

# Performing wavelet transform (and compute scalogram)
cwt_scipy = wa_scipy.cwt(batch)
cwt_torch = wa_torch.cwt(batch)

# For plotting, see the examples/plot.py function.
# ...

Supported Wavelets

The wavelet implementations are taken from here. Default is the Morlet wavelet.

Benchmark

Performing parallel CWT computation on the GPU using PyTorch results in a significant speed-up. Increasing the batch size will give faster runtimes. The plot below shows a comaprison between the scipy versus torch implementation as function of the batch size N and input signal length. These results were obtained on a powerful Linux desktop with NVIDIA Titan X GPU.

Installation

Clone and install:

git clone https://github.com/tomrunia/PyTorchWavelets.git
cd PyTorchWavelets
pip install -r requirements.txt
python setup.py install

Requirements

  • Python 2.7 or 3.6 (other versions might also work)
  • Numpy (developed with 1.14.1)
  • Scipy (developed with 1.0.0)
  • PyTorch >= 0.4.0

The core of the PyTorch implementation relies on the torch.nn.Conv1d module.

License

MIT License

Copyright (c) 2018 Tom Runia ([email protected])

Permission 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.

You might also like...
Paddle implementation for "Highly Efficient Knowledge Graph Embedding Learning with Closed-Form Orthogonal Procrustes Analysis" (NAACL 2021)

ProcrustEs-KGE Paddle implementation for Highly Efficient Knowledge Graph Embedding Learning with Orthogonal Procrustes Analysis 🙈 A more detailed re

Code implementation of
Code implementation of "Sparsity Probe: Analysis tool for Deep Learning Models"

Sparsity Probe: Analysis tool for Deep Learning Models This repository is a limited implementation of Sparsity Probe: Analysis tool for Deep Learning

This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Information Maximization for Multimodal Sentiment Analysis, accepted at EMNLP 2021.
This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Information Maximization for Multimodal Sentiment Analysis, accepted at EMNLP 2021.

MultiModal-InfoMax This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Informa

DCA - Official Python implementation of Delaunay Component Analysis algorithm
DCA - Official Python implementation of Delaunay Component Analysis algorithm

Delaunay Component Analysis (DCA) Official Python implementation of the Delaunay

Autolfads-tf2 - A TensorFlow 2.0 implementation of Latent Factor Analysis via Dynamical Systems (LFADS) and AutoLFADS

autolfads-tf2 A TensorFlow 2.0 implementation of LFADS and AutoLFADS. Installati

An essential implementation of BYOL in PyTorch + PyTorch Lightning
An essential implementation of BYOL in PyTorch + PyTorch Lightning

Essential BYOL A simple and complete implementation of Bootstrap your own latent: A new approach to self-supervised Learning in PyTorch + PyTorch Ligh

RealFormer-Pytorch Implementation of RealFormer using pytorch
RealFormer-Pytorch Implementation of RealFormer using pytorch

RealFormer-Pytorch Implementation of RealFormer using pytorch. Includes comparison with classical Transformer on image classification task (ViT) wrt C

A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch

Mixup: Beyond Empirical Risk Minimization in PyTorch This is an unofficial PyTorch implementation of mixup: Beyond Empirical Risk Minimization. The co

A pytorch implementation of  Pytorch-Sketch-RNN
A pytorch implementation of Pytorch-Sketch-RNN

Pytorch-Sketch-RNN A pytorch implementation of https://arxiv.org/abs/1704.03477 In order to draw other things than cats, you will find more drawing da

Comments
  • Switch from deprecated scipy.misc.factorial

    Switch from deprecated scipy.misc.factorial

    Since scipy 1.0.0 scipy.misc.factorial has been deprecated in favour of scipy.special.factorial. It is no longer even present in scipy >= 1.3.0, causing an error on import.

    opened by ar4 2
  • RuntimeError: CUDA error: unspecified launch failure

    RuntimeError: CUDA error: unspecified launch failure

    Hi there, I am testing PyTorchWavelets with some minimal code snippets. Unfortunately I encountered the problem with the very first example :-(

    # filename is PyTorchWavelets_minitest.py
    import torch
    import numpy as np
    from wavelets_pytorch.transform import WaveletTransform        # SciPy version
    from wavelets_pytorch.transform import WaveletTransformTorch   # PyTorch version
    
    def test():
        dt = 0.1         # sampling frequency
        dj = 0.125       # scale distribution parameter
        batchsize = 32    #! this is where the problem comes. If the problem wont reproduce try increasing this number
        
        # Batch of signals to process
        batch = np.random.randn(batchsize,10000)
    
        wa_torch = WaveletTransformTorch(dt, dj, cuda=True)
        cwt_torch = wa_torch.cwt(batch)
    
        print(cwt_torch)
    
    if __name__ == "__main__":
        test()
    

    It will either give me CUDA error: unspecified launch failure:

    (base) xzc@HP-XZC D:\dev_workspace
    > python PyTorchWavelets_minitest.py
    Traceback (most recent call last):
      File "PyTorchWavelets_minitest.py", line 20, in <module>
        test()
      File "PyTorchWavelets_minitest.py", line 15, in test
        cwt_torch = wa_torch.cwt(batch)
      File "d:\Anaconda3\lib\site-packages\wavelets_pytorch-0.1-py3.6.egg\wavelets_pytorch\transform.py", line 310, in cwt
    RuntimeError: CUDA error: unspecified launch failure
    

    Or CUDA error: the launch timed out and was terminated

    (base) xzc@HP-XZC D:\dev_workspace
    > python PyTorchWavelets_minitest.py
    Traceback (most recent call last):
      File "PyTorchWavelets_minitest.py", line 20, in <module>
        test()
      File "PyTorchWavelets_minitest.py", line 15, in test
        cwt_torch = wa_torch.cwt(batch)
      File "d:\Anaconda3\lib\site-packages\wavelets_pytorch-0.1-py3.6.egg\wavelets_pytorch\transform.py", line 310, in cwt
    RuntimeError: CUDA error: the launch timed out and was terminated
    

    I am using pytorch 1.0.0, Python version 3.6.5 (both installed through anaconda) on a Windows 10 x64 host. I googled the words "CUDA error: the launch timed out and was terminated" and found this. Not sure if it is corresponding to what is described in that post.

    opened by y0umu 0
Owner
Tom Runia
Machine Learning
Tom Runia
Selective Wavelet Attention Learning for Single Image Deraining

SWAL Code for Paper "Selective Wavelet Attention Learning for Single Image Deraining" Prerequisites Python 3 PyTorch Models We provide the models trai

Bobo 9 Jun 17, 2022
Classifying audio using Wavelet transform and deep learning

Audio Classification using Wavelet Transform and Deep Learning A step-by-step tutorial to classify audio signals using continuous wavelet transform (C

Aditya Dutt 17 Nov 29, 2022
Delta Conformity Sociopatterns Analysis - Delta Conformity Sociopatterns Analysis

Delta_Conformity_Sociopatterns_Analysis ∆-Conformity is a local homophily measur

null 2 Jan 9, 2022
Streamlit App For Product Analysis - Streamlit App For Product Analysis

Streamlit_App_For_Product_Analysis Здравствуйте! Перед вами дашборд, позволяющий

Grigory Sirotkin 1 Jan 10, 2022
PyTorch implementation of the Deep SLDA method from our CVPRW-2020 paper "Lifelong Machine Learning with Deep Streaming Linear Discriminant Analysis"

Lifelong Machine Learning with Deep Streaming Linear Discriminant Analysis This is a PyTorch implementation of the Deep Streaming Linear Discriminant

Tyler Hayes 41 Dec 25, 2022
Implementation of StyleSpace Analysis: Disentangled Controls for StyleGAN Image Generation in PyTorch

StyleSpace Analysis: Disentangled Controls for StyleGAN Image Generation Implementation of StyleSpace Analysis: Disentangled Controls for StyleGAN Ima

Xuanchi Ren 86 Dec 7, 2022
ALBERT-pytorch-implementation - ALBERT pytorch implementation

ALBERT-pytorch-implementation developing... 모델의 개념이해를 돕기 위한 구현물로 현재 변수명을 상세히 적었고

BG Kim 3 Oct 6, 2022
InsightFace: 2D and 3D Face Analysis Project on MXNet and PyTorch

InsightFace: 2D and 3D Face Analysis Project on MXNet and PyTorch

Deep Insight 13.2k Jan 6, 2023
Vertical Federated Principal Component Analysis and Its Kernel Extension on Feature-wise Distributed Data based on Pytorch Framework

VFedPCA+VFedAKPCA This is the official source code for the Paper: Vertical Federated Principal Component Analysis and Its Kernel Extension on Feature-

John 9 Sep 18, 2022
Unofficial implementation of "TTNet: Real-time temporal and spatial video analysis of table tennis" (CVPR 2020)

TTNet-Pytorch The implementation for the paper "TTNet: Real-time temporal and spatial video analysis of table tennis" An introduction of the project c

Nguyen Mau Dung 438 Dec 29, 2022