Collection of measures and metrics for image quality assessment.
- Unified interface, which easy to use and extend.
- Written on pure PyTorch with bare minima of additional dependencies.
- Fast (GPU computations available) and reliable.
- Most metrics can be backpropagated for model optimization.
- Supports python 3.6-3.8
First group of metrics takes image or images as input, e.g PSNR, SSIM, BRISQUE. We have functional interface, which returns metric value and class interface, which allows to use any metric as a loss.
import torch
from piq import ssim, SSIMLoss
prediction = torch.rand(4, 3, 256, 256, requires_grad=True)
target = torch.rand(4, 3, 256, 256)
ssim_index: torch.Tensor = ssim(prediction, target, data_range=1.)
loss = SSIMLoss(data_range=1.)
output: torch.Tensor = loss(prediction, target)
output.backward()
Second group takes a list of image features e.g. IS, FID, KID.
Image features can be extracted by some feature extractor network separetely, or by using _compute_feats
method of a class. Note, that _compute_feats
consumes a dataloader of predefined format.
import torch
from torch.utils.data import DataLoader
from piq import FID
first_dl, second_dl = DataLoader(), DataLoader()
fid_metric = FID()
first_feats = fid_metric._compute_feats(first_dl)
second_feats = fid_metric._compute_feats(second_dl)
fid: torch.Tensor = fid_metric(first_feats, second_feats)
If you already have image features, use class interface for score computation:
import torch
from piq import FID
prediction_feats = torch.rand(10000, 1024)
target_feats = torch.rand(10000, 1024)
msid_metric = MSID()
msid: torch.Tensor = msid_metric(prediction_feats, target_feats)
For a full list of examples, see image metrics and feature metrics examles.
- Blind/Referenceless Image Spatial Quality Evaluator (BRISQUE)
- Content score
- Deep Image Structure and Texture Similarity measure (DISTS)
- Feature Similarity Index Measure (FSIM)
- Gradient Magnitude Similarity Deviation (GMSD)
- Haar Wavelet-Based Perceptual Similarity Index (HaarPSI)
- Learned Perceptual Image Patch Similarity measure (LPIPS)
- Mean Deviation Similarity Index (MDSI)
- Multi-Scale Structural Similarity (MS-SSIM)
- Multi-Scale Gradient Magnitude Similarity Deviation (MS-GMSD)
- Peak Signal-to-Noise Ratio (PSNR)
- Structural Similarity (SSIM)
- Style score
- Total Variation (TV)
- Visual Information Fidelity (VIF)
- Visual Saliency-induced Index (VSI)
- Frechet Inception Distance(FID)
- Geometry Score (GS)
- Inception Score(IS)
- Kernel Inception Distance(KID)
- Multi-Scale Intrinsic Distance (MSID)
PyTorch Image Quality (former PhotoSynthesis.Metrics) helps you to concentrate on your experiments without the boilerplate code. The library contains a set of measures and metrics that is constantly getting extended. For measures/metrics that can be used as loss functions, corresponding PyTorch modules are implemented.
$ pip install piq
$ conda install piq -c photosynthesis-team -c conda-forge -c pytorch
If you want to use the latest features straight from the master, clone the repo:
$ git clone https://github.com/photosynthesis-team/piq.git
See the open issues for a list of proposed features and known issues.
We appreciate all contributions. If you plan to:
- contribute back bug-fixes, please do so without any further discussion
- close one of open issues, please do so if no one has been assigned to it
- contribute new features, utility functions or extensions, please first open an issue and discuss the feature with us
Please see the contribution guide for more information.
Sergey Kastryulin - @snk4tr - snk4tr@gmail.com
Project Link: https://github.com/photosynthesis-team/piq
PhotoSynthesis Team: https://github.com/photosynthesis-team
Other projects by PhotoSynthesis Team:
- Pavel Parunin - @PavelParunin - idea proposal and development
- Djamil Zakirov - @zakajd - development
- Denis Prokopenko - @denproc - development