Skip to main content

FDWT: Fast Multidimensional Discrete Wavelet Transform Layers (PyTorch)

PyPI Version PyPI Python PyTorch CUDA License

Fast 1D, 2D, and 3D Discrete Wavelet Transform (DWT) and Inverse DWT (IDWT) layers for backpropagation networks. Drop-in nn.Module layers with einsum-based fast computation. CPU and GPU ready.

Supported wavelet families

Haar (haar)          Daubechies (db)      Symlets (sym)
Coiflets (coif)      Biorthogonal (bior)  Reverse biorthogonal (rbio)

Shape requirements

  • Single-level: dimensions must be even. 2D and 3D inputs must be square / cubic.
  • Multilevel (L levels): each spatial side must be divisible by 2^L. Pad to the nearest multiple of 2^L when needed.

Installation

pip install fdwt

From source:

git clone https://github.com/kkt-ee/FDWT.git
cd FDWT
pip install .

Quick start

1D — (batch, N, channels)

from dwt import DWT1D, IDWT1D

lh   = DWT1D(wave='bior3.1')(x)   # (B, N, C) -> (B, N/2, C*2)
xhat = IDWT1D(wave='bior3.1')(lh) # (B, N/2, C*2) -> (B, N, C)

2D — (batch, H, W, channels)

from dwt import DWT2D, IDWT2D

lh   = DWT2D(wave='bior1.3')(x)   # (B, H, W, C) -> (B, H/2, W/2, C*4)
xhat = IDWT2D(wave='bior1.3')(lh) # (B, H/2, W/2, C*4) -> (B, H, W, C)

3D — (batch, D, H, W, channels)

from dwt import DWT3D, IDWT3D

lh   = DWT3D(wave='bior1.3')(x)   # (B, D, H, W, C) -> (B, D/2, H/2, W/2, C*8)
xhat = IDWT3D(wave='bior1.3')(lh) # (B, D/2, H/2, W/2, C*8) -> (B, D, H, W, C)

clean=True (default) packs subbands along the channel axis and halves spatial dims. clean=False returns the raw operator output at full spatial size.


Tensor shapes

Module Input Output (clean=True)
DWT1D (B, N, C) (B, N/2, C×2) — L || H
DWT2D (B, H, W, C) (B, H/2, W/2, C×4) — LL | LH | HL | HH
DWT3D (B, D, H, W, C) (B, D/2, H/2, W/2, C×8) — 8 subbands
IDWT1D (B, N/2, C×2) (B, N, C)
IDWT2D (B, H/2, W/2, C×4) (B, H, W, C)
IDWT3D (B, D/2, H/2, W/2, C×8) (B, D, H, W, C)

All layouts are channels-last.


Multilevel DWT

Returns a list [H1, H2, ..., H_level, L_level]. Each Hi contains all high-pass subbands at level i packed along the channel axis. The last element is the final low-pass residual.

1D

from dwt.multilevel.dwt1 import dwt, idwt

subbands = dwt(x, level=3, wave='haar')   # [H1, H2, H3, L3]
xhat     = idwt(subbands, wave='haar')

2D

from dwt.multilevel.dwt2 import dwt2, idwt2

subbands = dwt2(x, level=3, wave='haar')  # [H1, H2, H3, L3]
xhat     = idwt2(subbands, wave='haar')

3D

from dwt.multilevel.dwt3 import dwt3, idwt3

subbands = dwt3(x, level=2, wave='haar')  # [H1, H2, L2]
xhat     = idwt3(subbands, wave='haar')

Using the single-level and multilevel transforms, arbitrary multilevel filter banks and Wavelet Packet Transform filter banks can be constructed.


Use as a PyTorch layer in a model

import torch.nn as nn
from dwt import DWT2D, IDWT2D

class WaveletAutoencoder(nn.Module):
    def __init__(self):
        super().__init__()
        self.enc = DWT2D(wave='db4')
        self.dec = IDWT2D(wave='db4')

    def forward(self, x):
        return self.dec(self.enc(x))

Verified dependencies

Python   3.12+
PyTorch  2.0+  (verified on 2.7)
CUDA     12+

Uninstall

pip uninstall fdwt

FDWT (C) 2026 Kishore Kumar Tarafdar, भारत 🇮🇳

Metadata

Release files for fdwt 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fdwt 0.1.0
File Size Uploaded Provenance
fdwt-0.1.0.tar.gz 57.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fdwt 0.1.0
File Interpreter ABI Platform
fdwt-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 119.3 kB

Release files / fdwt-0.1.0.tar.gz

Download URL fdwt-0.1.0.tar.gz
Size 57.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a939a9091df858f911dadab068fcdd4272ba82ff87578e8991fd59142dfdf78f
BLAKE2b-256 checksum
How to use checksums
65e5e0e70057a4bdf1479ec9fe2d9e82c941696705458dab77d66e89dd483393
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / fdwt-0.1.0-py3-none-any.whl

Download URL fdwt-0.1.0-py3-none-any.whl
Size 61.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e5eebb9791785555abc26f1fe4ed88c51d474b0e0d3fb746592ce152ad27b01
BLAKE2b-256 checksum
How to use checksums
f057a4fbd1ecea74829962804a457e3ad72684db9409bc54145852629180ee21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for fdwt 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page