Skip to main content

Measures and metrics for image2image tasks. PyTorch.

Project description

piq_logo

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

Getting started

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 class.
Important note: 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)

For a full list of examples, see image metrics and feature metrics examples.

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. Perceptual Image-Error Assessment through Pairwise Preference (PieAPP)
  13. Structural Similarity (SSIM)
  14. Style score
  15. Total Variation (TV)
  16. Visual Information Fidelity (VIF)
  17. 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)

Overview

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.

Installation

$ 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

Roadmap

See the open issues for a list of proposed features and known issues.

Community

Contributing

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.

Contacts

Sergey Kastryulin - @snk4tr - snk4tr@gmail.com
Djamil Zakirov - @zakajd - djamilzak@gmail.com
Denis Prokopenko - @denproc - d.prokopenko@outlook.com

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.4.tar.gz (75.6 kB view hashes)

Uploaded Source

Built Distribution

piq-0.5.4-py3-none-any.whl (102.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page