Skip to main content

PyTorch Image Quality Assessment

Project description

PIQA is not endorsed by Facebook, Inc.; PyTorch, the PyTorch logo and any related marks are trademarks of Facebook, Inc.

PyTorch Image Quality Assessment

The piqa package is a collection of measures and metrics for image quality assessment in various image processing tasks such as denoising, super-resolution, image interpolation, etc. It relies only on PyTorch and takes advantage of its efficiency and automatic differentiation.

PIQA is directly inspired from the piq project, but focuses on the conciseness, readability and understandability of its (sub-)modules, such that anyone can easily reuse and/or adapt them to its needs.

However, conciseness should never be at the expense of efficiency; PIQA's implementations are up to 3 times faster than those of other IQA PyTorch packages like kornia, piq and IQA-pytorch.

PIQA should be pronounced pika (like Pikachu ⚡️)

Installation

The piqa package is available on PyPI, which means it is installable with pip:

pip install piqa

Alternatively, if you need the latest features, you can install it using

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

or copy the package directly to your project, with

git clone https://github.com/francois-rozet/piqa
cp -R piqa/piqa <path/to/project>/piqa

Documentation

The documentation of this package is generated automatically by Sphinx.

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.

import torch

# PSNR
from piqa import PSNR

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

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

# SSIM
from piqa import SSIM

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

ssim = 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.

import torch

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

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

kernel = gaussian_kernel(11, sigma=1.5).repeat(3, 1, 1)

l = ssim(x, y, kernel=kernel, channel_avg=False)

Metrics

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

JIT

Most functional components of piqa support PyTorch's JIT, i.e. TorchScript, which is a way to create serializable and optimizable functions from PyTorch code.

By default, jitting is disabled for those components. To enable it, the PIQA_JIT environment variable has to be set to 1. To do so temporarily,

  • UNIX-like bash
export PIQA_JIT=1
  • Windows cmd
set PIQA_JIT=1
  • Microsoft PowerShell
$env:PIQA_JIT=1

Assert

PIQA uses type assertions to raise meaningful messages when an object-oriented component 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

from piqa.utils import set_debug
set_debug(False)

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

piqa-1.2.2.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

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

piqa-1.2.2-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file piqa-1.2.2.tar.gz.

File metadata

  • Download URL: piqa-1.2.2.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for piqa-1.2.2.tar.gz
Algorithm Hash digest
SHA256 68eedbcc774f375abf016f7d5fcdd76a74e988a7f49543d07ecda6a2b0015dd2
MD5 c6d515baa2aad4b244a4f86dfbc68470
BLAKE2b-256 791ea9cdf440fb9a78d281786e54c2b5c005f6aa7d2e38708d7ff31c9432f195

See more details on using hashes here.

File details

Details for the file piqa-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: piqa-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for piqa-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8330b8ec132b2415b8f1654215499962ff763f5d1f49ef9e475dbf97ef184df8
MD5 6f5e71293f4a7169e6d830b3ad976a41
BLAKE2b-256 7ca5896d71032295e6c16b99b6218f3180d8320ec6d33db887b42bdcc6cc4255

See more details on using hashes here.

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