Skip to main content

Measures and metrics for image2image tasks. PyTorch.

Project description


License PyPI version Conda version
CI flake-8 style check CI testing codecov
Quality Gate Status Maintainability Rating Reliability Rating

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

Getting started

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)

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

Image metrics

  1. Blind/Referenceless Image Spatial Quality Evaluator (BRISQUE)
  2. Content score
  3. Deep Image Structure and Texture Similarity measure (DISTS)
  4. Feature Similarity Index Measure (FSIM)
  5. Gradient Magnitude Similarity Deviation (GMSD)
  6. Haar Wavelet-Based Perceptual Similarity Index (HaarPSI)
  7. Learned Perceptual Image Patch Similarity measure (LPIPS)
  8. Mean Deviation Similarity Index (MDSI)
  9. Multi-Scale Structural Similarity (MS-SSIM)
  10. Multi-Scale Gradient Magnitude Similarity Deviation (MS-GMSD)
  11. Peak Signal-to-Noise Ratio (PSNR)
  12. Structural Similarity (SSIM)
  13. Style score
  14. Total Variation (TV)
  15. Visual Information Fidelity (VIF)
  16. Visual Saliency-induced Index (VSI)

Feature metrics

  1. Frechet Inception Distance(FID)
  2. Geometry Score (GS)
  3. Inception Score(IS)
  4. Kernel Inception Distance(KID)
  5. 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


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 -

Project Link:
PhotoSynthesis Team:

Other projects by PhotoSynthesis Team:


  • Pavel Parunin - @PavelParunin - idea proposal and development
  • Djamil Zakirov - @zakajd - development
  • Denis Prokopenko - @denproc - development

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

piq-0.5.2.tar.gz (72.3 kB view hashes)

Uploaded source

Built Distribution

piq-0.5.2-py3-none-any.whl (96.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page