Wavelet-based loss calculations
Project description
Wavelet Loss
A Python library for wavelet-based loss calculations in machine learning.
Installation
pip install git+https://github.com/rockerBOO/wavelet-loss.git
Usage
Quick Start
import torch
from wavelet_loss import WaveletLoss
# Frequency-aware loss for VAE latents [B, C, H, W]
loss_fn = WaveletLoss(wavelet="db4", level=2, transform_type="dwt")
prediction = torch.randn(2, 4, 32, 32, requires_grad=True)
target = torch.randn(2, 4, 32, 32)
loss, metrics = loss_fn(prediction, target) # scalar loss (reduce=True default)
loss.backward()
Diffusion / flow-matching training
Pass the current timestep to fade out high-frequency loss at high noise levels:
# Flow-matching sigmas in [0, 1] (default convention)
loss_fn = WaveletLoss(wavelet="db4", level=2)
loss, metrics = loss_fn(prediction, target, timestep=timesteps)
# DDPM-style integer timesteps require max_timestep=1000
loss_fn = WaveletLoss(wavelet="db4", level=2, max_timestep=1000)
See docs/configurations.md for timestep_cutoff,
timestep_transition_width, and other options.
Features
- Discrete Wavelet Transform (DWT)
- Quadrature Wavelet Transform (QWT)
- Stationary Wavelet Transform (SWT)
- Wavelet-based loss calculations
- Timestep-aware loss weighting for diffusion / flow-matching training
Upgrading to 2.0
See CHANGELOG.md for breaking changes: normalize_bands now
defaults to False, forward returns a scalar by default (reduce=True),
metrics are opt-in (metrics=True), and timesteps are validated against
max_timestep (default 1.0, flow-matching convention).
Development
- Run tests:
uv run pytest - Python 3.10+ required
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wavelet_loss-2.0.0.tar.gz.
File metadata
- Download URL: wavelet_loss-2.0.0.tar.gz
- Upload date:
- Size: 157.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1043b55f50e7dc52e089e77be7cb19c143b21f288c509cb1749b20fdf642cd30
|
|
| MD5 |
392836ea3f94e6dfeafb8daa41a74026
|
|
| BLAKE2b-256 |
39b3d86ad721703fa654024ee7d420620a652d0d64e97445f507a6141fa1e3b4
|
Provenance
The following attestation bundles were made for wavelet_loss-2.0.0.tar.gz:
Publisher:
release.yml on rockerBOO/wavelet-loss
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wavelet_loss-2.0.0.tar.gz -
Subject digest:
1043b55f50e7dc52e089e77be7cb19c143b21f288c509cb1749b20fdf642cd30 - Sigstore transparency entry: 2041631103
- Sigstore integration time:
-
Permalink:
rockerBOO/wavelet-loss@575ba0c83f5bf0d16771191bca73a42a468d12e9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rockerBOO
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@575ba0c83f5bf0d16771191bca73a42a468d12e9 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file wavelet_loss-2.0.0-py3-none-any.whl.
File metadata
- Download URL: wavelet_loss-2.0.0-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08ffec350dbb832e79cbd2cb32e4a54cc85d0e2f473acdb94d969c3301f677e9
|
|
| MD5 |
7d67621468d65e0e49f850fac91c284e
|
|
| BLAKE2b-256 |
616edeec66135c678f3ae2aa53b3d863042c415c13e259c264b8e1fed7cd8a15
|
Provenance
The following attestation bundles were made for wavelet_loss-2.0.0-py3-none-any.whl:
Publisher:
release.yml on rockerBOO/wavelet-loss
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wavelet_loss-2.0.0-py3-none-any.whl -
Subject digest:
08ffec350dbb832e79cbd2cb32e4a54cc85d0e2f473acdb94d969c3301f677e9 - Sigstore transparency entry: 2041631333
- Sigstore integration time:
-
Permalink:
rockerBOO/wavelet-loss@575ba0c83f5bf0d16771191bca73a42a468d12e9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/rockerBOO
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@575ba0c83f5bf0d16771191bca73a42a468d12e9 -
Trigger Event:
workflow_dispatch
-
Statement type: