Skip to main content

PyTorch Image Quality Assessment

PIQA is a collection of PyTorch metrics for image quality assessment in various image processing tasks such as generation, denoising, super-resolution, interpolation, etc. It focuses on the efficiency, conciseness and understandability of its (sub-)modules, such that anyone can easily reuse and/or adapt them to its needs.

PIQA should be pronounced pika (like Pikachu ⚡️)

Installation

The piqa package is available on PyPI, which means it is installable via pip.

pip install piqa

Alternatively, if you need the latest features, you can install it from the repository.

pip install git+https://github.com/francois-rozet/piqa

Getting started

In piqa, each metric is associated to a class, child of torch.nn.Module, which has to be instantiated to evaluate the metric. All metrics are differentiable and support CPU and GPU (CUDA).

import torch
import piqa

# PSNR
x = torch.rand(5, 3, 256, 256)
y = torch.rand(5, 3, 256, 256)

psnr = piqa.PSNR()
l = psnr(x, y)

# SSIM
x = torch.rand(5, 3, 256, 256, requires_grad=True).cuda()
y = torch.rand(5, 3, 256, 256).cuda()

ssim = piqa.SSIM().cuda()
l = 1 - ssim(x, y)
l.backward()

Like torch.nn built-in components, these classes are based on functional definitions of the metrics, which are less user-friendly, but more versatile.

from piqa.ssim import ssim
from piqa.utils.functional import gaussian_kernel

kernel = gaussian_kernel(11, sigma=1.5).repeat(3, 1, 1)
ss, cs = ssim(x, y, kernel=kernel)

For more information, check out the documentation at piqa.readthedocs.io.

Available metrics

Class Range Objective Year Metric
TV [0, ∞] / 1937 Total Variation
PSNR [0, ∞] max / Peak Signal-to-Noise Ratio
SSIM [0, 1] max 2004 Structural Similarity
MS_SSIM [0, 1] max 2004 Multi-Scale Structural Similarity
LPIPS [0, ∞] min 2018 Learned Perceptual Image Patch Similarity
GMSD [0, ∞] min 2013 Gradient Magnitude Similarity Deviation
MS_GMSD [0, ∞] min 2017 Multi-Scale Gradient Magnitude Similarity Deviation
MDSI [0, ∞] min 2016 Mean Deviation Similarity Index
HaarPSI [0, 1] max 2018 Haar Perceptual Similarity Index
VSI [0, 1] max 2014 Visual Saliency-based Index
FSIM [0, 1] max 2011 Feature Similarity
FID [0, ∞] min 2017 Fréchet Inception Distance

Tracing

All metrics of piqa support PyTorch's tracing, which optimizes their execution, especially on GPU.

ssim = piqa.SSIM().cuda()
ssim_traced = torch.jit.trace(ssim, (x, y))

l = 1 - ssim_traced(x, y)  # should be faster ¯\_(ツ)_/¯

Assert

PIQA uses type assertions to raise meaningful messages when a metric doesn't receive an input of the expected type. This feature eases a lot early prototyping and debugging, but it might hurt a little the performances. If you need the absolute best performances, the assertions can be disabled with the Python flag -O. For example,

python -O your_awesome_code_using_piqa.py

Alternatively, you can disable PIQA's type assertions within your code with

piqa.utils.set_debug(False)

Contributing

If you have a question, an issue or would like to contribute, please read our contributing guidelines.

Metadata

Release files for piqa 1.3.2

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

Source distribution (sdist)

Source distribution for piqa 1.3.2
File Size Uploaded
piqa-1.3.2.tar.gz 23.9 kB Details

Built distribution (wheel)

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

Total release size: 56.0 kB

Release files / piqa-1.3.2.tar.gz

Download URL piqa-1.3.2.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
354aff428a1b69ceda26870e4a6d128c67ce75b6ff7ce4cf07d9a309b2ce681f
BLAKE2b-256 checksum
How to use checksums
e9abf0b2461b7d9d184c6c20cc1ce459471614af63879d50b9dd11150c791bd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / piqa-1.3.2-py3-none-any.whl

Download URL piqa-1.3.2-py3-none-any.whl
Size 32.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8b605a64877622a9ac8b300a695824e9f878faeddf9b9a69d39ea281f763fd0
BLAKE2b-256 checksum
How to use checksums
c9b81bb688ce6f31c00af4ea69277932bf6861ab6db41c6b2f02303756508478
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.1.8

1 release file

1.1.7

2 release files

1.1.3

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.7

2 release files

1.0.5

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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