Fast Scattering Transform with CuPy/PyTorch

Overview

Announcement

11/18

This package is no longer supported. We have now released kymatio: http://www.kymat.io/ , https://github.com/kymatio/kymatio which includes 1D-2D-3D fast, optimized, differentiable Scattering Transform and subsumes all the behavior of pyscatwave. Among other things you can now more easily use differentiable 2d scattering and use the CPU if desired. kymatio will be well supported with a substantially larger development team than pyscatwave.

07/18

We just released a differentiable 2D Scattering example in the master. It is not memory efficient yet, neither fast.

PyScatWave

CuPy/PyTorch Scattering implementation

A scattering network is a Convolutional Network with filters predefined to be wavelets that are not learned and it can be used in vision task such as classification of images. The scattering transform can drastically reduce the spatial resolution of the input (e.g. 224x224->14x14) with demonstrably neglible loss in dicriminative power.

The software uses PyTorch + NumPy FFT on CPU, and PyTorch + CuPy + CuFFT on GPU.

Previous (lua-based) versions of the code can be found at https://github.com/edouardoyallon/scatwave

If using this code for your research please cite our paper:

E. Oyallon, E. Belilovsky, S. Zagoruyko Scaling the Scattering Transform: Deep Hybrid Networks

You can find experiments from the paper in the following repository: https://github.com/edouardoyallon/scalingscattering/

We used PyTorch for running experiments in https://arxiv.org/abs/1703.08961, but it is possible to use scattering with other frameworks (e.g. Chainer, Theano or Tensorflow) if one copies Scattering outputs to CPU (or run on CPU and convert to numpy.ndarray via .numpy()).

Benchmarks

We do some simple timings and comparisons to the previous (multi-core CPU) implementation of scattering (ScatnetLight). We benchmark the software using a 1080 GPU. Below we show input sizes (WxHx3xBatchSize) and speed:

32 × 32 × 3 × 128 (J=2)- 0.03s (speed of 8x vs ScatNetLight)

256 × 256 × 3 × 128 (J=2) - 0.71 s (speed up of 225x vs ScatNetLight)

Installation

The software was tested on Linux with anaconda Python 2.7 and various GPUs, including Titan X, 1080s, 980s, K20s, and Titan X Pascal.

The first step is to install pytorch following instructions from http://pytorch.org, then you can run pip:

pip install -r requirements.txt
python setup.py install

Usage

Example:

import torch
from scatwave.scattering import Scattering

scat = Scattering(M=32, N=32, J=2).cuda()
x = torch.randn(1, 3, 32, 32).cuda()

print scat(x).size()

Contribution

All contributions are welcome.

Authors

Edouard Oyallon, Eugene Belilovsky, Sergey Zagoruyko

Comments
  • cublasNotInitialized

    cublasNotInitialized

    All the drivers/modules have been installed and verified. It throws an 'cublasNotInitialized' error when I run scat(x).
    Though, I can run skcuda.cublas.cublasCreate() in python.

    bug 
    opened by shiningsurya 13
  • Tensorflow re-implementation

    Tensorflow re-implementation

    I was curious to see what would happen if one could backprop through the Scattering transform (in the context of GANs for instance) so I ended up re-implementing your code in pure TF.

    Whenever I used or modified your work, I added a link to your repo. Is this enough to respect the clauses of the BSD license or should I add an explicit copyright notice ?

    My eventual Hybrid GANs were not very successful unfortunately...

    enhancement wontfix 
    opened by tdeboissiere 10
  • Speed and FLOPs Information

    Speed and FLOPs Information

    Hi,

    I don't know if this the right place to ask but I was wondering if you have information regarding the number of FLOPs performed by the scattering network.

    I am running tests on a model that has 22GFLOPs (using inception as the feature extractor + a few other big convolutions). I replaced the whole feature extractor by the scattering network with J=3 and input size of 368x368 (same as the original model).

    My results show that even if the GFLOPs count of the network wen from 22 to 5 in the hybrid network, inference time is 200 times slower using the Scattering network.

    Is this an expected result? Thank you,

    opened by aesadde 9
  • run pyscatwave without cuda

    run pyscatwave without cuda

    I tried to install pyscatwave, but do not have CUDA (so I cannot install skcuda). I can run python setup.py install without issue, but when I run import scatwave I get the following

    ---------------------------------------------------------------
    ImportError                   Traceback (most recent call last)
    <ipython-input-2-a2d06b630338> in <module>()
    ----> 1 import scatwave
    
    ~/anaconda/lib/python3.5/site-packages/scatwave-0.0.1-py3.5.egg/scatwave/__init__.py in <module>()
          6 
          7 
    ----> 8 from .scattering import Scattering
          9 from . import utils
    
    ~/anaconda/lib/python3.5/site-packages/scatwave-0.0.1-py3.5.egg/scatwave/scattering.py in <module>()
          8 import warnings
          9 import torch
    ---> 10 from .utils import cdgmm, Modulus, Periodize, Fft
         11 from .filters_bank import filters_bank
         12 from torch.legacy.nn import SpatialReflectionPadding as pad_function
    
    ~/anaconda/lib/python3.5/site-packages/scatwave-0.0.1-py3.5.egg/scatwave/utils.py in <module>()
          6 
          7 import torch
    ----> 8 from skcuda import cublas, cufft
          9 from pynvrtc.compiler import Program
         10 import numpy as np
    
    ImportError: No module named 'skcuda'
    

    Is it possible to simply remove this dependency and still run pyscatwave? Or would it be significantly more complicated than that?

    opened by asberk 6
  • Is calculating a derivative possible?

    Is calculating a derivative possible?

    Hi, Good work with this technique! I think its use could be expanded beyond simple feed-forward classifiers. In particular, I think it could be useful in generative neural networks.

    Is there a means to calculate a gradient through this such that this module could be used as an intermediate part of a larger computation graph?

    Best wishes, Michael

    opened by lolz0r 4
  • Implementation of pyscatwave using DL library primitives

    Implementation of pyscatwave using DL library primitives

    Thanks for releasing that code !

    I have not analyzed the scattering implementation thoroughly so this may not be a well-informed question but would it be feasible to write a pure pytorch (or tensorflow or theano for that matter) implementation using only the library's primitives ?

    If it is, have you tried such an implementation and was the performance satisfying?

    question 
    opened by tdeboissiere 4
  • Cant find cuda driver

    Cant find cuda driver

    Cant find cuda driver: However, I do have pytorch working in this virtualenv.

    ---------------------------------------------------------------------------
    OSError                                   Traceback (most recent call last)
    <ipython-input-244-a2d06b630338> in <module>()
    ----> 1 import scatwave
    
    /home/rafael/code/pyscatwave/scatwave/__init__.py in <module>()
          6 
          7 
    ----> 8 from .scattering import Scattering
          9 from . import utils
    
    /home/rafael/code/pyscatwave/scatwave/scattering.py in <module>()
          8 import warnings
          9 import torch
    ---> 10 from .utils import cdgmm, Modulus, Periodize, Fft
         11 from .filters_bank import filters_bank
         12 from torch.legacy.nn import SpatialReflectionPadding as pad_function
    
    /home/rafael/code/pyscatwave/scatwave/utils.py in <module>()
          6 
          7 import torch
    ----> 8 from skcuda import cublas, cufft
          9 from pynvrtc.compiler import Program
         10 import numpy as np
    
    /home/rafael/.virtualenvs/cvndev/local/lib/python2.7/site-packages/skcuda/cublas.py in <module>()
         20 from string import Template
         21 
    ---> 22 from . import cuda
         23 from . import utils
         24 
    
    /home/rafael/.virtualenvs/cvndev/local/lib/python2.7/site-packages/skcuda/cuda.py in <module>()
          8 
          9 from .cudart import *
    ---> 10 from .cudadrv import *
    
    /home/rafael/.virtualenvs/cvndev/local/lib/python2.7/site-packages/skcuda/cudadrv.py in <module>()
         30         break
         31 if _libcuda == None:
    ---> 32     raise OSError('CUDA driver library not found')
         33 
         34 # Exceptions corresponding to various CUDA driver errors:
    
    OSError: CUDA driver library not found
    
    
    bug 
    opened by kmichaelkills 4
  • Inverse of Scattering Transform

    Inverse of Scattering Transform

    I'm curious how you might reverse the scatter transform? For example, perform the scatter operation on an image, then do the inverse and get the image back. Is that possible?

    opened by rbunn80110 3
  • Weird unpredictable behaviour

    Weird unpredictable behaviour

    Hi! I tried using the lib and got some weird unpredictable behaviour. I just created a matrix A, computed the scattering transform of A and 1.01*A, and printed the ratio between the two outputs. ` A = torch.FloatTensor(np.ones((1,1,4,4)))

    A[0,0,0,0]=3

    scat = Scattering(M=4, N=4, J=2).cpu()

    res1 = scat(A).numpy().copy().squeeze()

    res2 = scat(1.01*A).numpy().copy().squeeze()

    print(res2/res1) `

    When I repeat this code, which as far as I understand should always give the same result, I get totally different matrices. Sometimes with an order of magnitude of 1, sometimes 10^{-3}, 10^{25}, 10^{20} etc. I checked and there is no 'rand' function in your code, what the hell is it doing? ^^

    opened by MendesO 3
  • which part is gaussian smoothing?

    which part is gaussian smoothing?

    Not quite an issue but a question I have on the code: where is the gaussian smoothing implemented? My guess is the Phi filter, but that doesn't look like a gaussian filter. What am I missing?

    opened by angelleng 3
  • MNIST example is incorrect

    MNIST example is incorrect

    I see you based your code off of "https://github.com/pytorch/tnt/blob/master/example/mnist.py".

    You forgot to reset the "classerr" meter. So when you call "engine.test", the accuracy that is printed out is the average classification accuracy of testing and training, not just testing.

    opened by sebastiankmiec 2
  • About the problems of scattering network

    About the problems of scattering network

    Hello,

    Thanks a lot for your generous sharing.

    I want to use your proposed structure in some adversarial training framework.

    My problem is that:

    When batch size is 64, the previous data has the size of 64332*32

    For J=1, after scattering, the matrix size is 64391616. For J=2, after scattering, the matrix size is 6431788. For J=3, after scattering, the matrix size is 6432544. For J=4, after scattering, the matrix size is 6433322.

    Looks like the tensor-shape for third dimesion is 1+J*8, the fourth and fifth dimension is 32/2^j.

    I am not sure, is there a inverse operation API that I can restore the matrix after scattering to the original matrix, e.g., Tensor with size 64332*32.

    I am sorry for double submitting issues.

    However, I am not sure which repository would be in fix.

    Thanks & regards! Momo

    opened by momo1986 0
Owner
Edouard Oyallon
Applied maths guy
Edouard Oyallon
Hough Transform and Hough Line Transform Using OpenCV

Hough transform is a feature extraction method for detecting simple shapes such as circles, lines, etc in an image. Hough Transform and Hough Line Transform is implemented in OpenCV with two methods; the Standard Hough Transform and the Probabilistic Hough Line Transform.

Happy  N. Monday 3 Feb 15, 2022
Minimal deep learning library written from scratch in Python, using NumPy/CuPy.

SmallPebble Project status: experimental, unstable. SmallPebble is a minimal/toy automatic differentiation/deep learning library written from scratch

Sidney Radcliffe 92 Dec 30, 2022
Fast Neural Style for Image Style Transform by Pytorch

FastNeuralStyle by Pytorch Fast Neural Style for Image Style Transform by Pytorch This is famous Fast Neural Style of Paper Perceptual Losses for Real

Bengxy 81 Sep 3, 2022
MINIROCKET: A Very Fast (Almost) Deterministic Transform for Time Series Classification

MINIROCKET: A Very Fast (Almost) Deterministic Transform for Time Series Classification

null 187 Dec 26, 2022
DCT-Mask: Discrete Cosine Transform Mask Representation for Instance Segmentation

DCT-Mask: Discrete Cosine Transform Mask Representation for Instance Segmentation This project hosts the code for implementing the DCT-MASK algorithms

Alibaba Cloud 57 Nov 27, 2022
Simple Python application to transform Serial data into OSC messages

SerialToOSC-Bridge Simple Python application to transform Serial data into OSC messages. The current purpose is to be a compatibility layer between ha

Division of Applied Acoustics at Chalmers University of Technology 3 Jun 3, 2021
Style transfer, deep learning, feature transform

FastPhotoStyle License Copyright (C) 2018 NVIDIA Corporation. All rights reserved. Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons

NVIDIA Corporation 10.9k Jan 2, 2023
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
Python tools for 3D face: 3DMM, Mesh processing(transform, camera, light, render), 3D face representations.

face3d: Python tools for processing 3D face Introduction This project implements some basic functions related to 3D faces. You can use this to process

Yao Feng 2.3k Dec 30, 2022
OpenCV, MediaPipe Pose Estimation, Affine Transform for Icon Overlay

Yoga Pose Identification and Icon Matching Project Goal Detect yoga poses performed by a user and overlay a corresponding icon image. Running the main

Anna Garverick 1 Dec 3, 2021
Build an Amazon SageMaker Pipeline to Transform Raw Texts to A Knowledge Graph

Build an Amazon SageMaker Pipeline to Transform Raw Texts to A Knowledge Graph This repository provides a pipeline to create a knowledge graph from ra

AWS Samples 3 Jan 1, 2022
Perform zero-order Hankel Transform for an 1D array (float or real valued).

perform zero-order Hankel Transform for an 1D array (float or real valued). An discrete form of Parseval theorem is guaranteed. Suit for iterative problems.

null 1 Jan 17, 2022
Projecting interval uncertainty through the discrete Fourier transform

Projecting interval uncertainty through the discrete Fourier transform This repo

null 1 Mar 2, 2022
A Python library that enables ML teams to share, load, and transform data in a collaborative, flexible, and efficient way :chestnut:

Squirrel Core Share, load, and transform data in a collaborative, flexible, and efficient way What is Squirrel? Squirrel is a Python library that enab

Merantix Momentum 249 Dec 7, 2022
Super-Fast-Adversarial-Training - A PyTorch Implementation code for developing super fast adversarial training

Super-Fast-Adversarial-Training This is a PyTorch Implementation code for develo

LBK 26 Dec 2, 2022
Implementation of fast algorithms for Maximum Spanning Tree (MST) parsing that includes fast ArcMax+Reweighting+Tarjan algorithm for single-root dependency parsing.

Fast MST Algorithm Implementation of fast algorithms for (Maximum Spanning Tree) MST parsing that includes fast ArcMax+Reweighting+Tarjan algorithm fo

Miloš Stanojević 11 Oct 14, 2022
FAST-RIR: FAST NEURAL DIFFUSE ROOM IMPULSE RESPONSE GENERATOR

This is the official implementation of our neural-network-based fast diffuse room impulse response generator (FAST-RIR) for generating room impulse responses (RIRs) for a given acoustic environment.

Anton Jeran Ratnarajah 89 Dec 22, 2022
Fit Fast, Explain Fast

FastExplain Fit Fast, Explain Fast Installing pip install fast-explain About FastExplain FastExplain provides an out-of-the-box tool for analysts to

null 8 Dec 15, 2022
PyTorch-LIT is the Lite Inference Toolkit (LIT) for PyTorch which focuses on easy and fast inference of large models on end-devices.

PyTorch-LIT PyTorch-LIT is the Lite Inference Toolkit (LIT) for PyTorch which focuses on easy and fast inference of large models on end-devices. With

Amin Rezaei 157 Dec 11, 2022