Measures and metrics for image2image tasks. PyTorch.
Project description
PyTorch Image Quality (PIQ) is not endorsed by Facebook, Inc.;
PyTorch, the PyTorch logo and any related marks are trademarks of Facebook, Inc.
PyTorch Image Quality (PIQ) is a collection of measures and metrics for image quality assessment. PIQ 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.
We provide:
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.
PIQ was initially named PhotoSynthesis.Metrics.
Installation
PyTorch Image Quality (PIQ) can be installed using pip, conda or git.
If you use pip, you can install it with:
$ pip install piq
If you use conda, you can install it with:
$ conda install piq -c photosynthesis-team -c conda-forge -c PyTorch
If you want to use the latest features straight from the master, clone PIQ repo:
git clone https://github.com/photosynthesis-team/piq.git
cd piq
python setup.py install
Documentation
The full documentation is available at https://piq.readthedocs.io.
Usage Examples
Image-based metrics
The group of metrics (such as PSNR, SSIM, BRISQUE) takes image or images as input. We have a functional interface, which returns a metric value, and a class interface, which allows to use any metric as a loss function.
import torch
from piq import ssim, SSIMLoss
x = torch.rand(4, 3, 256, 256, requires_grad=True)
y = torch.rand(4, 3, 256, 256)
ssim_index: torch.Tensor = ssim(x, y, data_range=1.)
loss = SSIMLoss(data_range=1.)
output: torch.Tensor = loss(x, y)
output.backward()
For a full list of examples, see image metrics examples.
Feature-based metrics
The group of metrics (such as IS, FID, KID) takes a list of image features. Image features can be extracted by some feature extractor network separately or by using the compute_feats method of a class.
- 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
x_feats = torch.rand(10000, 1024)
y_feats = torch.rand(10000, 1024)
msid_metric = MSID()
msid: torch.Tensor = msid_metric(x_feats, y_feats)
For a full list of examples, see feature metrics examples.
List of metrics
Full Reference
Acronym |
Year |
Metric |
---|---|---|
PSNR |
- |
|
SSIM |
2003 |
|
MS-SSIM |
2004 |
|
VIFp |
2004 |
|
FSIM |
2011 |
|
SR-SIM |
2012 |
|
GMSD |
2013 |
|
VSI |
2014 |
|
DSS |
2015 |
|
- |
2016 |
|
- |
2016 |
|
HaarPSI |
2016 |
|
MDSI |
2016 |
|
MS-GMSD |
2017 |
|
LPIPS |
2018 |
|
PieAPP |
2018 |
Perceptual Image-Error Assessment through Pairwise Preference |
DISTS |
2020 |
No Reference
Acronym |
Year |
Metric |
---|---|---|
TV |
1937 |
|
BRISQUE |
2012 |
Feature based
Acronym |
Year |
Metric |
---|---|---|
IS |
2016 |
|
FID |
2017 |
|
GS |
2018 |
|
KID |
2018 |
|
MSID |
2019 |
|
PR |
2019 |
Benchmark
As part of our library we provide code to benchmark all metrics on a set of common Mean Opinon Scores databases. Currently we support TID2013, KADID10k and PIPAL. You need to download them separately and provide path to images as an argument to the script.
Here is an example how to evaluate SSIM and MS-SSIM metrics on TID2013 dataset:
python3 tests/results_benchmark.py --dataset tid2013 --metrics SSIM MS-SSIM --path ~/datasets/tid2013 --batch_size 16
We report Spearman’s Rank Correlation cCoefficient (SRCC) and Kendall rank correlation coefficient (KRCC). We do not report Pearson linear correlation coefficient (PLCC) as it’s highly dependent on fitting method and is biased towards simple examples.
For metrics that can take greyscale or colour images, c means chromatic version.
TID2013 |
KADID10k |
PIPAL |
||||
---|---|---|---|---|---|---|
Acronym |
SRCC / KRCC (PIQ) |
SRCC / KRCC |
SRCC / KRCC (PIQ) |
SRCC / KRCC |
SRCC / KRCC (PIQ) |
SRCC / KRCC |
PSNR |
0.687 / 0.496 |
0.687 / 0.496 TID2013 |
0.676 / 0.488 |
- / - |
0.407 / 0.276 |
0.407 / 0.277 PIPAL |
SSIM |
0.720 / 0.527 |
0.637 / 0.464 TID2013 |
0.724 / 0.537 |
0.718 / 0.532 KADID10k |
0.498 / 0.345 |
0.529 / 0.369 PIPAL |
MS-SSIM |
0.798 / 0.597 |
0.787 / 0.608 TID2013 |
0.802 / 0.609 |
0.802 / 0.609 KADID10k |
0.552 / 0.389 |
0.462 / - |
VIFp |
0.610 / 0.458 |
0.610 / 0.457 TID2013 |
0.650 / 0.477 |
0.650 / 0.477 KADID10k |
0.497 / 0.345 |
- / - |
FSIM |
0.802 / 0.629 |
0.801 / 0.630 TID2013 |
0.830 / 0.639 |
0.829 / 0.639 KADID10k |
0.588 / 0.415 |
0.596 / 0.421 PIPAL |
FSIMc |
0.851 / 0.667 |
0.851 / 0.667 TID2013 |
0.854 / 0.665 |
0.854 / 0.665 KADID10k |
0.590 / 0.416 |
- / - |
SR-SIM |
0.807 / 0.641 |
0.808 / 0.641 Eval2019 |
0.839 / 0.652 |
0.839 / 0.652 KADID10k |
0.565 / 0.399 |
- / - |
SR-SIMc |
0.870 / 0.692 |
- / - |
0.869 / 0.685 |
- / - |
0.569 / 0.401 |
- / - |
GMSD |
0.804 / 0.633 |
0.803 / 0.635 MS-GMSD |
0.847 / 0.664 |
0.847 / 0.664 KADID10k |
0.584 / 0.414 |
- / - |
VSI |
0.895 / 0.716 |
0.897 / 0.718 Eval2019 |
0.878 / 0.690 |
0.861 / 0.678 KADID10k |
0.539 / 0.375 |
- / - |
DSS |
0.791 / 0.614 |
0.792 / - Eval2019 |
0.860 / 0.674 |
0.860 / 0.674 KADID10k |
0.632 / 0.456 |
- / - |
Content |
0.705 / 0.517 |
- / - |
0.724 / 0.533 |
- / - |
0.450 / 0.307 |
- / - |
Style |
0.538 / 0.372 |
- / - |
0.647 / 0.465 |
- / - |
0.343 / 0.231 |
- / - |
HaarPSI |
0.873 / 0.692 |
0.873 / 0.692 HaarPSI |
0.885 / 0.700 |
0.885 / 0.699 KADID10k |
0.589 / 0.417 |
- / - |
MDSI |
0.890 / 0.712 |
0.890 / 0.712 MDSI |
0.885 / 0.702 |
0.885 / 0.702 KADID10k |
0.585 / 0.408 |
- / - |
MS-GMSD |
0.812 / 0.646 |
0.814 / 0.647 MS-GMSD |
0.852 / 0.669 |
- / - |
0.585 / 0.414 |
- / - |
MS-GMSDc |
0.888 / 0.711 |
0.687 / 0.496 MS-GMSD |
0.870 / 0.683 |
- / - |
0.587 / 0.416 |
- / - |
LPIPS-VGG |
0.670 / 0.497 |
0.670 / 0.497 DISTS |
0.720 / 0.531 |
- / - |
0.573 / 0.404 |
0.577 / 0.408 PIPAL |
PieAPP |
0.836 / 0.650 |
0.875 / 0.710 DISTS |
0.866 / 0.676 |
- / - |
0.698 / 0.509 |
0.711 / 0.521 PIPAL |
DISTS |
0.805 / 0.613 |
0.830 / 0.639 DISTS |
0.875 / 0.695 |
- / - |
0.617 / 0.438 |
0.664 / 0.477 PIPAL |
Assertions
In PIQ we use assertions to raise meaningful messages when some component doesn’t receive an input of the expected type. This makes prototyping and debugging easier, but it might hurt the performance. To disable all checks, use the Python -O flag: python -O your_script.py
Roadmap
See the open issues for a list of proposed features and known issues.
Contributing
If you would like to help develop this library, you’ll find more information in our contribution guide.
Citation
If you use PIQ in your project, please, cite it as follows.
@misc{piq,
title={{PyTorch Image Quality}: Metrics and Measure for Image Quality Assessment},
url={https://github.com/photosynthesis-team/piq},
note={Open-source software available at https://github.com/photosynthesis-team/piq},
author={Sergey Kastryulin and Dzhamil Zakirov and Denis Prokopenko},
year={2019},
}
Contacts
Sergey Kastryulin - @snk4tr - snk4tr@gmail.com
Djamil Zakirov - @zakajd - djamilzak@gmail.com
Denis Prokopenko - @denproc - d.prokopenko@outlook.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.