Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wavelet_loss-2.0.0.tar.gz (157.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wavelet_loss-2.0.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

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

Hashes for wavelet_loss-2.0.0.tar.gz
Algorithm Hash digest
SHA256 1043b55f50e7dc52e089e77be7cb19c143b21f288c509cb1749b20fdf642cd30
MD5 392836ea3f94e6dfeafb8daa41a74026
BLAKE2b-256 39b3d86ad721703fa654024ee7d420620a652d0d64e97445f507a6141fa1e3b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for wavelet_loss-2.0.0.tar.gz:

Publisher: release.yml on rockerBOO/wavelet-loss

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for wavelet_loss-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08ffec350dbb832e79cbd2cb32e4a54cc85d0e2f473acdb94d969c3301f677e9
MD5 7d67621468d65e0e49f850fac91c284e
BLAKE2b-256 616edeec66135c678f3ae2aa53b3d863042c415c13e259c264b8e1fed7cd8a15

See more details on using hashes here.

Provenance

The following attestation bundles were made for wavelet_loss-2.0.0-py3-none-any.whl:

Publisher: release.yml on rockerBOO/wavelet-loss

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page