Collection of measures and metrics for image quality assessment.
- Unified interface, which is easy to use and extend.
- Written on pure PyTorch with bare minima of additional dependencies.
- Extensive user input validation. You code will not crash in the middle of the training.
- Fast (GPU computations available) and reliable.
- Most metrics can be backpropagated for model optimization.
- Supports python 3.6-3.8.
The first group of metrics takes image or images as input, e.g., PSNR, SSIM, BRISQUE. We have a functional interface, which returns a metric value, and a class interface, which allows us to use any metric as a loss function.
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()
The second group takes a list of image features, e.g., IS, FID, KID.
Image features can be extracted by some feature extractor network separately or by using the
compute_feats method of a
compute_feats consumes a data loader of a 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 the 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)
- 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)
- Perceptual Image-Error Assessment through Pairwise Preference (PieAPP)
- 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 continually 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 your 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.