Laplacian and Gaussian pyramid loss functions for PyTorch
Project description
pyramid-loss
PyTorch implementation of Laplacian and Gaussian pyramid for seismic data.
Installation
pip install pyramid-loss
Usage
Build Pyramids
import torch
from pyramid_loss import gaussian_kernel, create_laplacian_pyramid, create_gaussian_pyramid
ns = 3
nt = 100
nr = 300
x = torch.rand(1, ns, nt, nr)
size = 5 ### Kernel Size
channels = x.shape[1]
sigma = 3 ### Standard Deviation
levels = 5 ### number of level
kernel = gaussian_kernel(size=size, channels=channels, sigma=sigma)
lap_pyr = create_laplacian_pyramid(x, kernel, levels=levels)
gau_pyr = create_gaussian_pyramid(x, kernel, levels=levels)
Compute Loss
from pyramid_loss import PyramidLoss
loss_fn = PyramidLoss(
pyramid = 'laplacian', # 'laplacian' | 'gaussian'
loss = 'l1', # 'l1' | 'l2'
levels = levels,
channels = channels,
use_weights = True, # False → weight=1 for all levels
# True → weight=2^level per level (default)
weights = [1.0, 2.0, 4.0, 8.0, 16.0], # or pass custom weights
)
y = torch.rand(1, 3, 256, 256)
loss = loss_fn(x, y)
References
- [1] gonglixue — LaplacianLoss-pytorch
- [2] Burt, P. J., & Adelson, E. H. (1987). The Laplacian Pyramid as a Compact Image Code. Readings in Computer Vision, pp. 671–679, Elsevier.
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
pyramid_loss-0.1.1.tar.gz
(5.1 kB
view details)
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 pyramid_loss-0.1.1.tar.gz.
File metadata
- Download URL: pyramid_loss-0.1.1.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f5216bd57ac1f61b5483331e8f8c3e1b2d2c0287a2f6b3de23adb5c2b44313
|
|
| MD5 |
7e8af58809de90a087d3392c33312a56
|
|
| BLAKE2b-256 |
447b8500103dca0be632719c5795d539b704d525c8f49a581a71b287811fffc9
|
File details
Details for the file pyramid_loss-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyramid_loss-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc4afe9112b4c2e6b381773e55e3612166a93793c1444f045a3c1613bc3b405b
|
|
| MD5 |
49f85fb8c5cf4165e99cdb3b9d5ecd52
|
|
| BLAKE2b-256 |
c240e5549b00c2c759733ec4cbe5a0eee8fdb2a2053d20a7287fd7c90121621d
|