Laplacian and Gaussian pyramid loss functions for PyTorch
Project description
pyramid-loss
Laplacian and Gaussian pyramid loss functions for PyTorch.
Installation
pip install pyramid-loss
Usage
PyramidLoss
import torch
from pyramid_loss import PyramidLoss
loss_fn = PyramidLoss(
pyramid='laplacian', # 'laplacian' 或 'gaussian'
loss='l1', # 'l1', 'l2' 或自定义 callable
levels=3,
channels=3,
)
x = torch.rand(2, 3, 256, 256)
target = torch.rand(2, 3, 256, 256)
# 只要总 loss
loss = loss_fn(x, target)
# 同时要每层 loss(方便 logging)
loss, per_level = loss_fn(x, target, return_per_level=True)
create pyramids
import torch
from pyramid_loss import gaussian_kernel, create_laplacian_pyramid, create_gaussian_pyramid
x = torch.rand(1, 3, 256, 256)
kernel = gaussian_kernel(size=5, channels=3, sigma=1.0)
lap_pyr = create_laplacian_pyramid(x, kernel, levels=3)
gaus_pyr = create_gaussian_pyramid(x, kernel, levels=3)
weight loss
loss_fn = PyramidLoss(
pyramid='laplacian',
loss='l1',
levels=3,
channels=3,
use_weights=True,
weights=[1.0, 2.0, 4.0, 8.0], # 长度 = levels + 1
)
License
MIT
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.0.tar.gz
(4.7 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.0.tar.gz.
File metadata
- Download URL: pyramid_loss-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6dcb63f001d9ed20f370aff5c0d8401cafc0ec5d15fcd72de9001bdaae9debe
|
|
| MD5 |
1610148a7b7fa464883a27ed0864e93d
|
|
| BLAKE2b-256 |
7a790e6c8945b73e2a5e0d97ae7ad17ada19a66d6df240847212ce9e6d78e6e0
|
File details
Details for the file pyramid_loss-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyramid_loss-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.9 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 |
370dd6bebafe5bb0894901040b278ac781027661382bf7e8bdfd704cef5b3fa0
|
|
| MD5 |
d3e9f7a7e759592c6a7d8bb9376885d8
|
|
| BLAKE2b-256 |
9048c08bb9722b879d9e9eb724b48b65267c759425fc4b97893309ad1a4cc198
|